|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Hi:
I have a problem in getting innerText of iframe. I use this script: var inText = document.getElementById("f1").document.body.innerText; alert(inText); // After using this script i receive innerText of whole page, but not iframe. Then i use this: var inText = f1.document.body.innerText; alert(inText); // After using this i receive error message "Access Denied" Then i use this: var inText = document.frames("f1").document.body.innerText; alert(inText); // After using this i receive same error message "Access Denied" Can any body tell me what is going wrong? Thanks Burhan |
|
#2
|
|||
|
|||
|
First of all, document.getElementById("f1").document.body.innerText; is equal to document.body.innerText;.
Actually, document.location gives you the main page location and f1.location, the iframe-page location. document.body is an object, whereas f1 is an object and f1.body is undefined. document.body.innerText gives you the whole page content, whereas f1.body.innerText & f1.innerText are both undefined ! Conclusion : I don't understand anything ! In fact, I'm sure your problem and mine are linked. Grrrr ! |
|
#3
|
|||
|
|||
|
IFRAMES INTERACTING
I have spent several months improving my webPage and, yesterday, after deep progress (and many brain nodes since July), I've finally found the so expected solution to our common problem. I'll try to set it out to you, even if you've probably adopted an alternative option ever since then : self.document points the mainPage out. self.window points the documents set of the mainPage out AND the mainPage itself. It might be the leading difference between the two reserved words document & window. window represents a document when it is not indexed but, it also represents an Array of documents when it is. Let's consider a mainPage (which can be a frame or an iFrame itself) holding several iFrames ; self.window.length will return the number of contained iFrames as a value. If we want to focus on iFrame #1 from the mainPage, we must call to self.window[0] but, to catch its document up we must call to self.window[0].document. Considering all that, to have access to particular elements of iFrame #1 from the mainPage, follow this examples table indications : IFRAME #i ELEMENT -------------------- WAY TO CALL TO FROM THE MAINPAGE title ----------------------------------- self.window[i-1].document.title body HTML source --------------------- self.window[i-1].document.body.innerHTML value of an element the identifier of wich is object1 ---------- self.window[i-1].document.getElementById("object1").value PAY ATTENTION ! To launch the execution of a not argumented function of iFrame #1 named iFrame#1_FCT() from the mainPage, man has to call to self.window[0].iFrame#1_FCT(); as well as document.mainPage_FCT() is not a valid formulation. To go deeply from all that, launching an argumented function of iFrame #1 (with arguments also contained in iFrame #1) from the mainPage, the correct formulation is based on this schema : self.window[0].iFrame#1_argumentedFCT( self.window[0].document.getElementById("iFrame#1_argument").value );
where iFrame#1_argument can be the identifier of a valued div.
This solution to our problem is valid for IE as well as for NS5+ (I can't test it with NS4). I've tried to explain it more efficiently in this few pages. Hope it could be usefull. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > get innerText of iframe |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|