Let me get to the page where my js-скрипт works (connected via greasemonkey). Using it on the page I create an iframe element:

 var el = document.createElement("iframe"); el.id = "iframe"; el.style.width = "1000px"; el.style.height = "800px"; el.src = HrefLinkOnParentPage; document.body.appendChild(el); 

Naturally, there was a problem that the js namespace matches the parent-страницы and the child-страницы . Because of this, frames are recursively created in frames.

Is there any way to determine if the page is child or parent ? Those. after creating the frame for the first time, you need to determine that it is the frame of the main page and stop the execution of the script on it.

    1 answer 1

    Dug up the function: window.frameElement , which returns null if this document is not embedded in another, or else a reference to the element in which it is embedded:

     var frameEl = window.frameElement; if (frameEl==null) alert("main frame"); else alert("embedded frame"); 

    With this, you can distinguish the embedded frame from the main frame.