如何在Chrome浏览器中调用父窗口函数? [英] How to call parent window function in chrome browser?

查看:627
本文介绍了如何在Chrome浏览器中调用父窗口函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,
在Chrome浏览器中,我惊奇地发现问题是调用窗口父级JavaScript函数。
如果我有一个窗口,里面定义了一个javascript函数

I've surprisingly found problems, in Chrome browser, in calling window parent javascript functions. If I have a window with a javascript function defined in it

<script type="text/javascript">
  function dolink() {
   . . .
  }
</script>

,并且在该窗口中有一个 iframe ,它使用jquery

and I have an iframe inside that window that makes this call using jquery

<script type="text/javascript">
 $(function() {
      $('a.arglink').click(function() {
         window.parent.dolink($(this).attr('href'));
         return false;
      });
 });
</script>

dolink 函数的调用不起作用。使用chrome javascript调试器,看起来window.parent.dolink是 undefined 。这是我设计的还是一个错误?
在Firefox和IE中它工作正常。

the call to dolink function doesn't work. Stepping with chrome javascript debugger, it appears that window.parent.dolink is undefined. It's by design or a mistake that I made? In Firefox and IE it works fine.

推荐答案

终于找到了!

似乎Chrome浏览器不允许使用 file:协议访问访问网页的父窗口。事实上,我在上面的代码中测试了我的机器上的文件,所以像 file:/// C:/mytests/mypage.html 这样的URL。如果我把这个页面放到Web服务器上,它就可以按预期工作。

It seems that Chrome browser doesn't permit to reference a parent window accessing pages with the file: protocol. In fact I tested above code with files on my machine, so with a url like file:///C:/mytests/mypage.html . If I put that page in a Web Server, it all works as expected.

这篇关于如何在Chrome浏览器中调用父窗口函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆