Forum Moderators: coopster

Message Too Old, No Replies

Parsing an Iframe

         

cripplertd

4:10 am on Aug 29, 2007 (gmt 0)

10+ Year Member



is it possible?

Say you load google.com into an iframe then do a searh, then you have a button that when you click it, the script will read the new contents of the iframe and parse according to your script.

phparion

4:42 am on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



yes it is possible

cripplertd

4:46 am on Aug 29, 2007 (gmt 0)

10+ Year Member



is it difficult?

phparion

5:51 am on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you're, sorry to say, asking very difficult questions that one would not bother to reply to usually :).

I humbly request Mods to put a sticky here for posting guidelines.

anyway, to guide you, you can use javascript to read iframe body data into a variable and then you can parse it using any of the following.

var body = iframename.document.body.innerText;
var body = iframename.document.body.innerHTML;

now you have all the body text in a variable and you can do whatever you want to. you can use either pure javascript for parsing or send this variable to a php page from javascript, AJAX, for parsing.

I hope that helps.

vincevincevince

6:05 am on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will have great difficulty doing this due to security restrictions unless both the framing page and the framed page are on the same domain.

phparion

6:20 am on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I guess the FRAMED page doesn't need to be on the same server or same domain. he must have the FRAMING page and the BUTTON on his own domain then he can show any page in the frame and then by clicking on button (onclick event) he can call a function which can read the body of the iframe that is showing the page and it will read the page loaded into that frame as text.. i haven't tried it yet but I guess this is how it should work.

vincevincevince

6:26 am on Aug 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am afraid it does not work. It must be on the same domain, or you will get a permission denied error if you try to read the contents of that IFRAME.

cripplertd

7:01 am on Aug 29, 2007 (gmt 0)

10+ Year Member



really? I wanted to do it via frames so you physically login/ goto each page and grab the page source instead of messing with the scripting for login sites.

cripplertd

5:10 pm on Aug 29, 2007 (gmt 0)

10+ Year Member



saw this ealier, can you guys help me interupt it?

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.

So if I name my iframe "content" I would want to use this?

var content = self.window[content-1].document.body.innerHTML

How would I make that into a function so I can call it onclick, also, how do I do a print to screen so I can verifiy if it's fetching the right source?