Prev: Implicit object constructor misinterpretation
Next: Creating an Object that extends Array functionality
From: FAQ server on 24 Oct 2009 19:00 ----------------------------------------------------------------------- FAQ Topic - How do I access a frame's content? ----------------------------------------------------------------------- To reference another frame on the _same domain_: A frame's content window can be found from the ` frames ` collection. Example: var fwin; fwin = self.frames[0]; // or: fwin = self.frames["iframeName"]; or from the ` IFRAME ` or ` FRAME ` element: var iframeEl = document.getElementById("myFrame"); var fwin = iframeEl.contentWindow; An identifier ` moomin ` in the the iframe's content window, is accessed as ` fwin.moomin `. To communicate between frames on _different_ domains: Where supported, (IE8, Firefox 3, Opera 9, Safari 4), use ` window.postMessage( message[, port], otherDomain); `. Example: http://jibbering.com/faq/example/postMessage.html Where ` window.postMessage ` is not supported, the ` window.name ` property can be set on the other window, which can poll for updates to that property using ` setInterval(checkWinName, 100); ` where ` checkWinName ` is a function that polls to check the value of ` self.name `. http://en.wikipedia.org/wiki/Same_origin_policy http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html https://developer.mozilla.org/en/DOM/window.postMessage http://msdn.microsoft.com/en-us/library/cc197015(VS.85).aspx The complete comp.lang.javascript FAQ is at http://jibbering.com/faq/ -- The sendings of these daily posts are proficiently hosted by http://www.pair.com.
From: Dr J R Stockton on 25 Oct 2009 16:13 In comp.lang.javascript message <4ae386fe$0$279$14726298(a)news.sunsite.dk >, Sat, 24 Oct 2009 23:00:02, FAQ server <javascript(a)dotinternet.be> posted: >or from the ` IFRAME ` or ` FRAME ` element: > >var iframeEl = document.getElementById("myFrame"); >var fwin = iframeEl.contentWindow; > Perhaps it is worth subdividing, for clarity : How do I access the content of a frame or iframe Domain considerations Frame Iframe I've been accessing a page in an iframe with <iframe>.contentDocument.body.innerHTML // FF Op Sf Cr <iframe>.contentDocument.body.innerText // Not Firefox? but I there have no interest in accessing variables. Using IE8, the code fails at an earlier stage. In effect, I want to read the file, HTML or TXT, as it exists on disc. QUERY : disregarding unlikely server & browser settings, which extensions are taken to imply that the file can safely be read into an iframe and parsed or read textually there? (a) HTM HTML SHTML (b) TXT (c) *not* ZIP EXE GIF, for example. -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05. Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
From: VK on 25 Oct 2009 20:00 Dr J R Stockton wrote: > In effect, I want to read the file, HTML or TXT, as it exists on disc. You cannot do it for the reason explained at http://groups.google.com/group/comp.lang.javascript/msg/d9f3f6724bada573 To read HTML as it exists on disc you have to either i) read it over a plain text editor on the computer in question ii) read it as text input stream by using AJAX request. Anything else simply generates a request to the browser parser to read the existing DOM Tree resulted from the original page and to back- parse it to HTML code by the match rules of this particular parser. The results normally are as an Old Slavonic being translated to Mandarin and from Mandarin to English by a Spanish native speaker. > QUERY : disregarding unlikely server & browser settings, which > extensions are taken to imply that the file can safely be read into an > iframe and parsed or read textually there? see above > (c) *not* ZIP EXE GIF, for example. > > -- > (c) John Stockton, nr London, UK. ?...@merlyn.demon.co.uk Turnpike v6.05. > Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms > PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm > Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
From: Dr J R Stockton on 26 Oct 2009 15:22 In comp.lang.javascript message <963d3089-ac6c-47a7-8fec-e2f5f3617de5(a)l3 4g2000vba.googlegroups.com>, Sun, 25 Oct 2009 17:00:29, VK <schools_ring(a)yahoo.com> posted: >Dr J R Stockton wrote: >> In effect, I want to read the file, HTML or TXT, as it exists on disc. > >You cannot do it for the reason explained at > http://groups.google.com/group/comp.lang.javascript/msg/d9f3f6724bada573 Unconvincing, because I *am* doing it, to the extent that is essential for the task. If you consider under what circumstances what can work, you should be able to deduce how and why I am doing it. >To read HTML as it exists on disc you have to either > i) read it over a plain text editor on the computer in question i.i) use TYPE or MORE at the command line i.ii) read it with a text viewer >ii) read it as text input stream by using AJAX request. > >Anything else simply generates a request to the browser parser to read >the existing DOM Tree resulted from the original page and to back- >parse it to HTML code by the match rules of this particular parser. Note, though, that "want" can mean more than "need". I want to read as on disc, certainly; but my needs are substantially satisfied for TXT files by what innerText and innerHTML show, and for HTML files by what is actually revealed. It's annoying that Firefox seems to lack innerText of iframe content, so that the output of innerHTML has to be used and purified before use. FYI, the unanswered "missing page" detection which I raised on 2009-10-15 is now fully dealt with. >> -- >> �(c) DQS -- (c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME. Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links. Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036) Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
From: Thomas 'PointedEars' Lahn on 27 Oct 2009 14:38
Dr J R Stockton wrote: > I want to read as on disc, certainly; but my needs are substantially > satisfied for TXT files by what innerText and innerHTML show, and for > HTML files by what is actually revealed. > > It's annoying that Firefox seems to lack innerText of iframe content, It implements the `textContent' property instead, like any other browser standards-compliant in that regard. (Discussed here ad nauseam). Suppose `iframe' refers to the object implementing the HTMLIFrameElement interface, then you are looking for iframe.contentDocument.documentElement.textContent That is, if the layout engine (like Gecko) wraps the content of a text/plain resource in a markup (HTML-like) document. More precise would be iframe.contentDocument.body.textContent then. I remember to have posted that explanation before, but the FAQ had not been updated for some reason. > so that the output of innerHTML has to be used and purified before use. Non sequitur. PointedEars -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.) |