Forum Moderators: open

Message Too Old, No Replies

Using IndexOf to parse iframe source code

How can this be done from the containing page?

         

j4mes

7:06 pm on Jun 6, 2004 (gmt 0)

10+ Year Member



I've written a quick piece of js to generate a random url from an array (long story... :P). I now want to be able to parse the soure of this iframe for text strings, so obviously I used IndexOf to do this.

Unfortunately all I seem to be able to get is the URL that's being generated, which isn't much help since I already know it(!)

I can post some code if it helps to explain the problem.

Thanks.

Bernard Marx

8:30 pm on Jun 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have I got it right?

You have an array of URL strings. You direct your IFRAME to a URL picked at random from the array. You then want to find particular pieces of text in in the sourcecode of the document you have loaded into the IFRAME.

1. You know that...
You can only access the document in the IFRAME if it's from the same domain as your page

2. How do you know when the IFRAME has loaded so that you can access it without error?

3. Do you need wide support, or will IE be enough for your current project?

4. Do you need/want to access documents outside your domain?

j4mes

8:50 pm on Jun 6, 2004 (gmt 0)

10+ Year Member



Hi Bernard Marx,

That's right, you understood my ramblings exactly! In answer to your questions,

1) No, I didn't know that, can it be got round?

2) I am using onload to make sure, which only = true when the page is fully loaded.

3) This is a personal project, so whatever browser works is what I'll use. I'm using IE at the moment because it allows for my sloppy coding! :P

4) Yes, the domain is Google's, and just http (not secure or a weird protocol or anything).

Thanks.

Rambo Tribble

4:12 am on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Basically, due to the "Same Origin Policy", which all browsers adhere to, you can't touch a page from another domain. It's a security feature implemented both with JavaScript and Java applets. No way around, over or through it. That is, unless you write your own browser, or, perhaps, plug-in. Just maybe (though I sincerely doubt it), Java Web Start applications could give you some limited functionality in this regard.

Teknorat

4:20 am on Jun 7, 2004 (gmt 0)

10+ Year Member



I know what this is for!

Bernard Marx

7:04 am on Jun 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Tribble's right, as usual: You can't touch a page from another domain - one that's in another browser window/frame. This would be a security risk, because some nasties could have his page read things on another page like:

1. Information that you enter into forms.
2. See where you go surfing.

...and send it back to them.

However, the good news is that you can get at the document straight from the server. You need to use an XMLHTTPrequest. I'll be stickying you some useful code shortly.

j4mes

4:06 pm on Jun 7, 2004 (gmt 0)

10+ Year Member



I know what this is for!

Better share it with everyone else, so you can all see what I'm talking about...

[webmasterworld.com...] (Post #19)

I'll be stickying you some useful code shortly.

Thanks Bernard Marx, it'll be much appreciated.

j4mes

5:14 pm on Jun 7, 2004 (gmt 0)

10+ Year Member



Bernard that's fantastic, thanks! :)