javascript - Open window from iframe - Stack Overflow

This is the situation. I'm trying to provide a service where someone embedds an iframe on their we

This is the situation. I'm trying to provide a service where someone embedds an iframe on their website with a form in it. At the end when an ajax request es in again I want to pop a new window with a thank you note in it. window.open does not work and my guess is because the window object belongs to the page that embedds it and not the iframe and would then be considered cross-site scripting. Is there another way of doing this?

A thought I had was, that I can create links with target="_new" in my iframe, and clicking that would actually pop another window. Maybe I could create this link and "click"/trigger it with javascript?

I do have control over what the user embedds so potentially I could include a script there too, but the less code there, the better obviously.

Any takes?

This is the situation. I'm trying to provide a service where someone embedds an iframe on their website with a form in it. At the end when an ajax request es in again I want to pop a new window with a thank you note in it. window.open does not work and my guess is because the window object belongs to the page that embedds it and not the iframe and would then be considered cross-site scripting. Is there another way of doing this?

A thought I had was, that I can create links with target="_new" in my iframe, and clicking that would actually pop another window. Maybe I could create this link and "click"/trigger it with javascript?

I do have control over what the user embedds so potentially I could include a script there too, but the less code there, the better obviously.

Any takes?

Share Improve this question asked Mar 15, 2010 at 20:00 miccetmiccet 1,9003 gold badges20 silver badges27 bronze badges 2
  • 1 You're probably being blocked by a popup blocker. – SLaks Commented Mar 15, 2010 at 20:02
  • IIRC the popup is being blocked because it is being triggered from an XHR onreadystatechange event and not from a user triggered event. Browsers are designed to stop popups appearing which are not user triggered. – Quentin Commented Mar 15, 2010 at 20:03
Add a ment  | 

1 Answer 1

Reset to default 7

window.open does not work and my guess is because the window object belongs to the page that embeds it

I don't think so. window as seen by your script will generally be the window object of the document inside the iframe.

More typically, a window.open on an XMLHttpRequest pletion will be blocked by browsers' built-in pop-up-blockers. They usually only allow new windows to be opened in direct response to user interaction (typically, in the onclick event handler).

Maybe I could create this link and "click"/trigger it with javascript?

No, otherwise everyone would be doing that to circumvent blockers!

If you're starting an XHR and you know you're going to need a pop-up in the future you'll have to open it now and put some filler content in until the XHR returns, at which point you can update its contents.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742315819a4420816.html

相关推荐

  • javascript - Open window from iframe - Stack Overflow

    This is the situation. I'm trying to provide a service where someone embedds an iframe on their we

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信