English 中文(简体)
• 如何把母窗功能引向母子浏览器?
原标题:How to call parent window function in chrome browser?

HI, 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

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

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 http:///C:/mytests/mypage.html。 如果我把这个网页放在一个网络服务器上,那么它就能够发挥预期的作用。

问题回答

你们应该这样说。

if(function != undefined)
{
 $(function() {
      $( a.arglink ).click(function() {
         window.parent.dolink($(this).attr( href ));
         return false;
      });
 });
}

如何使用<条码>框架/编码>和<条码>所有文件

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

我只是这样做了。

一、背景

function sendToParent() {
    parent.doSomething(); 
}
sendToParent();

父母

function doSomething() {
    alert( did it! )
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签