English 中文(简体)
当儿童关闭时,如何将 parent本功能称作母窗?
原标题:How to call a JavaScript function of parent window when child is closed?

I am creating a pop-up window. After I am finished with the work on child (pop up) window and click close button, I need to call a JavaScript function of the parent window. How can I achieve this? I am not creating the child window myself but displaying the contents of some other URL.

最佳回答

我不认为你可以做一件事,因为当《URL》来自不同领域时,你可以拿文件本身。 但是,你可以污染并检查窗户的“封闭”财产:

var w = window.open("http://what.ever.com", "OtherWindow");
setTimeout(function() {
  if (w.closed) {
    // code that you want to run when window closes
  }
  else
    setTimeout(arguments.callee, 100);
}, 100);

如果你希望:

var w = window.open("http://what.ever.com", "OtherWindow");
var interval = setInterval(function() {
  if (w.closed) {
    // do stuff
    cancelInterval(interval);
  }
}, 100);
问题回答

如果儿童窗口不是源于与父母窗口相同的域名,则由于same origin policy而重新锁定。 这样做是为了防止交叉描述攻击。

Don。 仅改进点代码,删除<条码>标记。 Vote for Pointy.

var w = window.open("http://what.ever.com", "OtherWindow");
setTimeout(function timeout() {
  if (w.closed) {
    // code that you want to run when window closes
  }
  else
    setTimeout(timeout, 100);
}, 100);




相关问题
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.

热门标签