FireFox 不要从 jQuery 脚本取消表单提交
我有这样的情况:
<form class="reqSnip" action="snipvw" method="post" target="_blank">
<input type="hidden" name="a_snip" value="0">
<input type="hidden" name="b_snip" value="1">
<input type="hidden" name="fullDoc" value="true">
<button type="submit" class="getFullSnippet"></button>
</form>
所以 - 带有 3 个隐藏字段+提交按钮的基本表单。在 jQuery 的帮助下,我绑定到提交此表单的时刻并自定义流程:
jQuery('.reqSnip').submit(function() {
jQuery('#snipDIV').jqmShow(); // 1
return false; // 2
});
为了使图片清晰:
- // 1 - 在网页上打开一些“类似弹出”的窗口
- // 2 - 取消表单提交。我这样做是因为表格只要求一些 Ajax-info 且不得执行标准表单提交。为了我的 你可以思考这个问题,因为我只是不想提交表单 地方,所有 Ajax 的东西都与这个问题无关。
所有这些如何协同工作:
- 在 IE7/8/9/Chrome/Opera 中 - 一切如预期,弹出窗口打开,表单不打开 提交
- 在 FireFox(Windows XP SP3 上的版本 8.0.1)中 - 弹出窗口打开并从 DO 提交(因此新选项卡出现在浏览器中)
我在 javascript 调试器中进行了简单的调查(我只是在 // 1 和 // 2 行上放置了 2 个断点(BP))以及我发现的事实:
- IE7/8/9/Chrome/Opera - 在 // 1 行上点击 BP,然后在 // 2 行上点击 BP
- FireFox - 在 // 1 行上点击 BP 并且永远不要在 // 2 行上点击 BP,所以 命令“return false”从未执行过:(
那么 - 如何使 FF 行为与所有其他浏览器中相同?
PS 第 1 行中使用的库:
- jQuery - 你知道的:)
- jqmShow - 来自 jqModal 的命令,这是一个插件jQuery。它是 主页: http://dev.iceburg.net/jquery/jqModal
更新< /strong>
我找到了问题的根源... 根据 jqModal 文档(请参阅上面的链接),如果绑定到 onShow 事件,则必须在事件处理程序内显示(设置可见)对话框(我的“类似弹出”的窗口)。所以一般方案是
var myOpen=function(hash){ hash.w.css('opacity',0.88).show(); };
$('#dialog').jqm({onShow:myOpen});
....
$('#dialog').jqmShow();
我编写的代码非常接近于此。 所有浏览器都接受这种方法。 FF“不喜欢”它。不知道为什么。因此,为了解决我的问题,不要绑定到 onShow 事件就足够了。那是!
I have that situation:
<form class="reqSnip" action="snipvw" method="post" target="_blank">
<input type="hidden" name="a_snip" value="0">
<input type="hidden" name="b_snip" value="1">
<input type="hidden" name="fullDoc" value="true">
<button type="submit" class="getFullSnippet"></button>
</form>
So - basic form with 3 hidden field+button to submit. With the help of jQuery I bind to the moment of submit this form and customize the process:
jQuery('.reqSnip').submit(function() {
jQuery('#snipDIV').jqmShow(); // 1
return false; // 2
});
To make picture clear:
- // 1 - open some "pop-up-like" window over Web-page
- // 2 - cancel form submit. I do so since the form just request some
Ajax-info and must NOT perform standart form submission. For my
question you can think as I just don't want the form submission take
place, all Ajax-stuff is irrelevant for the question.
How all this works together:
- In IE7/8/9/Chrome/Opera - all as expected, pop-up open, form don't
submitted - In FireFox(ver. 8.0.1 on Windows XP SP3) - pop-up open and from DO
submitted (so new tab appear in browser)
I make a light investigation in javascript debuggers (I just place 2 breakpoints(BP) on lines // 1 and // 2) and facts I discover:
- IE7/8/9/Chrome/Opera - hit BP on line // 1, then BP on line // 2
- FireFox - hit BP on line // 1 and NEVER hit BP on line // 2, so
command 'return false' just never executed :(
So - how to make FF behaviour the same as in all others browsers?
P.S. Libraries used in line 1:
- jQuery - you know it :)
- jqmShow - command from jqModal, this is a plugin for jQuery. It's
home page: http://dev.iceburg.net/jquery/jqModal
UPDATE
I found root of the problem...
According jqModal documentation (see link above) if you bind to onShow event you must to show (set visible) the dialog (my "pop-up-like" window) inside the event handler. So the general scheme will be
var myOpen=function(hash){ hash.w.css('opacity',0.88).show(); };
$('#dialog').jqm({onShow:myOpen});
....
$('#dialog').jqmShow();
I wrote my code very close to this.
All browsers accept this approach. FF "dislike" it. Have no idea why. So, to solve my problem it is enough DON'T bind to onShow event. That is!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: