PDA

View Full Version : Help me load specific content from a remote page by using JavaScript



Dellius
05-14-2008, 11:40 AM
Help me load specific content from a remote page using JavaScript, please.

I need to load specific text value from a page located on a remote domain and replace that value in my HTML code.

I can load the remote page in a small 1x1 pixels iframe and I have a regular expression which I can use to find the content I need. I have little clue, however, on how to use JavaScript to extract the content from the page in the iframe.

Point me, please to some tutorials which can show me how to do it.

jscheuer1
05-14-2008, 03:02 PM
This may be illegal, copyright infringement. It is also an illegal operation, in that modern browsers will not allow communication between pages on different domains via javascript. It can't be done with javascript alone.

Dellius
05-15-2008, 02:23 PM
Thank you for your reply.

Yes, JavaScript alone can't do that, that's why I intend to load the page contents inside an iframe and save it in a variable.

jscheuer1
05-15-2008, 03:52 PM
The use of an iframe is immaterial, the page inside it is still on another domain.

Dellius
05-15-2008, 04:35 PM
I doubt that because the moment the page is loaded by a user's browser it is already located on their hard drive.

jscheuer1
05-15-2008, 04:50 PM
I doubt that because the moment the page is loaded by a user's browser it is already located on their hard drive.

Don't. It is, but javascript cannot access the user's hard drive either. It isn't a question of the values not being 'available'. It is a question of security measures in modern browsers. In the old days you could just use:


iframe_element_object.document.innerHTML

Where iframe_element_object is the iframe fetched via document.all or document.getElementById (or any method that 'gets' it as page element, as opposed to as a window frame) and parse that string using your favorite method to get what you are after. Or even:


iframe_element_object.document.getElementById('some_id').innerHTML

to query a particular element on the page's innerHTML. But this is no longer allowed or supported, except for pages that are both on the same domain.

Dellius
05-16-2008, 01:19 PM
Thank you for clarifying this for me, jscheuer1.