javascript - Close iframe cross domain -


I am trying to do something similar to a clipper application

I can appear in iframe Another website (cross domain) but I can not make the "close" button to work.

This is what I used to do but it does not work for the cross domain (basically removes the iframe element)

  window.parent.document.getElementById ( 'SomeId') parentNode.removeChild (window.parent.document.getElementById ('someId')).  

Can you help? Thank you.

You should use such a library, which is the summary (e.g., not tested) . Piece ID messages can not work in all browsers, and there are better ways, such as

However, using your example (klipper) hack, it can be a cross-browser, provided your page with iFrame is at the top level. In other words, there are two levels, in fact,

parent.html

& lt; Html & gt; & Lt; Top & gt; & Lt; Script type = "text / javascript" & gt; Function CheckForClos () (if (window.location.hash == "#close_child") {var someIframe = document.getElementById ("some ID"); someIframe.parentNode.removeChild (someIframe);} and {setTimeout (CheckforClos, 1000 }}} SetTimeout (CheckforClos, 1000); gt; body & gt; & lt; iframe name = "someId" id = "someId" src = " Child.html "height =" 800 "width =" 600 "& gt; foo & lt; / iframe & gt; & lt; / body & gt; & lt; / html & gt;

child.html:

   gt; top & gt; & lt; script type = "text / javascript"> setTimeout (function () {Window.parent.location.hash = "close_child";}, 5000); & lt; / script & gt; & lt; body style = "background-colo R: blue "& gt; & lt; / html> gt;  

EDIT2: Cross-domains and independently controlled are different. (Heavy mineral / opaque) opened the polywire code, to see how it works (coincidentally, it is not in Firefox). First of all remember that bookletslets, such as the clipper, live in the context of the page, when they start in this case, the bookmarklet load, which in turn triggers an init function that generates, but also runs: < / P>

  Event.addListener (Event.XFRAME, "done", cancel);  

If you dig into AdLostner, you will get ():

  if (_1ce2 == Event.XFRAME) {if (! _1cb3) { _1cb3 = new monitor (function () {return window.location.hash;}, 100); Event.adllist (_1cb3, "change", onshash); }}  

Canceled:

  removeNode (iframe); Now, the only remaining piece is that the ClipperForm.init function includes:  
  Event.addListener ($ ("close"), " Click ", function () {Event.postMessage (window.parent, _228d," done ");});  

So we clearly see that they are using piece ID messaging.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -