jQuery 点击事件不重定向到 href

发布于 2024-10-05 17:58:55 字数 1530 浏览 4 评论 0原文

我有一个嵌入 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">&nbsp;</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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

因为看清所以看轻 2024-10-12 17:58:56

查看 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 with javascript: links.

To do what you want, use ExternalInterface.call().

山色无中 2024-10-12 17:58:56

找到了执行此操作的正确方法(感谢 corneliu),所以我想将其发布回此处以供参考。在 html 文件中:

<script type="text/javascript">
   function viewDemo() {
      $.nyroModalManual({
         url: 'emailSend.aspx?Type=4'
      });           
   }
</script>

在 flash 文件中:

import flash.system.Security;

cmdDemo.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void {
   flash.system.Security.allowDomain("business.com");
   ExternalInterface.call("viewDemo");
}

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:

<script type="text/javascript">
   function viewDemo() {
      $.nyroModalManual({
         url: 'emailSend.aspx?Type=4'
      });           
   }
</script>

In the flash file:

import flash.system.Security;

cmdDemo.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void {
   flash.system.Security.allowDomain("business.com");
   ExternalInterface.call("viewDemo");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文