Saturday 15 May 2010

javascript - parent.document gives undefined in Chrome -


In my HTML pages, I have two-level child-to-haveifame hierarchy. I would like to have some manipulation in my hair document I want to get an object of the original window document. I work with Google Chrome.

The parent document 'undefined' in Google Chrome, while it works fine in Mozilla. What's the catch?

First of all, file: 'one.html'

For reference, please find the content of three files that display this problem below, / P>

  & lt; Html & gt; & Lt; Top & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Input type = "hidden" id = "one_1" name = "a_1" /> & Lt; Iframe id = "one" name = "one" src = "two.html" & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

Other files: 'two.html'

  & lt; Html & gt; & Lt; Top & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Input type = "hidden" id = "2_1" name = "2_1" /> & lt; Iframe id = "two" name = "two" src = "three.html" & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

Third file: 'three.html'

  & lt; Html & gt; & Lt; Top & gt; & Lt; Script type = "text / javascript" & gt; Function column () {warning (original document) warning (top.document)} & lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Input type = "hidden" id = "three_1" name = "three_1" /> & Lt; Button id = "click" name = "click" onclick = "return callme ()"> Click me & lt; / Button & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

The 'one.html' has been opened with Google Chrome, assuming that when I click on the 'Click Meet' button, two alert alert box 'undefined' value Appear with. When I open 'one.html' in Mozilla, two 'Object HTML Document' Valuable Alert Box appears.

Please find console messages below when clicking on the 'Click Meet' button,

  Try to reach the frame with an unsafe JavaScript URL file: /// C. : / Users / User / Descope / two.html With Frame With URL File: /// C: / Users / User / Desktop / Three Html Domains, protocols and ports must match. Trying to use the frame with three html.html columns: html: 6 onclick three.html: 13 unprotected Javascript url file: /// c: / Users / User / Desktop / From a frame with a URL file: // /C:/Users/user/Desktop/three.html. Domains, protocols and ports must match. 3.html: 7 ColMom three.html: 7 onclick three.html: 13   

Thanks in advance.

In contrast to reaching the bottom-up, I will inject from the top-bottom I select it in an iframe I'll set a variable and store it in a variable like this:

  var frame = document.getElementById ('one');   

And then enter a reference for parents:

  frame.contentWindow.frame_parent_reference = window;   

And then replace it with "two" in the next child iFrame, by the third, we do not ask for the parent or above, but the following tasks Can:

  Warning (frame_parent_reference document); Warning (frame_parent_reference.frame_parent_reference.document);   

is probably not super elegant but it certainly gives you a lot of control (and you can check whether custom reference is present for security or not).

Good luck!

No comments:

Post a Comment