jQuery 点击事件不重定向到 href
我有一个嵌入 Flash 影片的 HTML 页面,其中有一个按钮。 Flash 中的此按钮调用 lnkEmail 的单击事件。它应该停止实际导航到新页面,但是 event.preventDefault();从事件处理程序返回 false 似乎对我不起作用。任何人都可以提供见解吗?
下面的示例在 Chrome 中工作,但在 IE 7 和 FF 中失败。在这些浏览器中,它会重定向到一个以 Object [object] 作为正文的空白页面,而在 FF 中,它会将 url 设置为我从 Flash 影片中执行的 javascript 代码。 (即:“javascript:jQuery('#lnkEmail').click();”)
下面是 Flash ActionScript 中的代码。
cmdDemo.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
navigateToURL(
new URLRequest(
"javascript:jQuery('#lnkEmail').click();"
),
"_self"
);
}
在包含的 HTML 页面中,有以下脚本和元素:
<script type="text/javascript">
$(function(){
$.nyroModalSettings({
debug: true
});
$('#lnkEmail').click(function(event) {
event.preventDefault();
$.nyroModalManual({
url: 'demoRequest.aspx?Type=4'
});
return false;
});
});
</script>
稍后在同一文件中:
<div id="box_stage_home">
<script type="text/javascript">
$(document).ready(function() {
$('#HomeAnimation').flash({
swf: 'Flash/index_page.swf',
height: 288,
width: 686,
wmode: 'transparent'
});
});
</script>
<div id="HomeAnimation"><!--IE 6.0--></div>
<a href="emailSend.aspx?Type=4" id="lnkEmail"> </a>
</div>
I've got an HTML page with an embedded flash movie, which has a button. This button in flash invokes the lnkEmail's click event. It's supposed to stop from actually navigating to a new page, but the event.preventDefault(); and the returning of false from the event handler don't seem to be working for me. Can anyone provide insight?
The below example is working in Chrome, but fails in IE 7 and FF. In those browsers it redirects to a blank page with Object [object] as the body and in FF has the url set to the javascript code I execute from within the Flash movie. (ie: "javascript:jQuery('#lnkEmail').click();")
Below is the code in the Flash ActionScript.
cmdDemo.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
navigateToURL(
new URLRequest(
"javascript:jQuery('#lnkEmail').click();"
),
"_self"
);
}
In the containing HTML page there is the following scripts and elements:
<script type="text/javascript">
$(function(){
$.nyroModalSettings({
debug: true
});
$('#lnkEmail').click(function(event) {
event.preventDefault();
$.nyroModalManual({
url: 'demoRequest.aspx?Type=4'
});
return false;
});
});
</script>
And later in the same file:
<div id="box_stage_home">
<script type="text/javascript">
$(document).ready(function() {
$('#HomeAnimation').flash({
swf: 'Flash/index_page.swf',
height: 288,
width: 686,
wmode: 'transparent'
});
});
</script>
<div id="HomeAnimation"><!--IE 6.0--></div>
<a href="emailSend.aspx?Type=4" id="lnkEmail"> </a>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看
navigateToURL
文档:http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/package.html#navigateToURL%28%29。它不适合与javascript:
链接一起使用。要执行您想要的操作,请使用
ExternalInterface.call()
。Take a look at the
navigateToURL
documentation: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/package.html#navigateToURL%28%29. It is not intendend to be used withjavascript:
links.To do what you want, use
ExternalInterface.call()
.找到了执行此操作的正确方法(感谢 corneliu),所以我想将其发布回此处以供参考。在 html 文件中:
在 flash 文件中:
Figured out the proper way (thanks corneliu) to do this so thought I'd post it back on here for reference. In the html file:
In the flash file: