3

My apologies if this is a stupid question, but I spent hours searching with no results.

I would like to look at the raw HTML of a document without it being rendered by the browser. Is there a DOM element that does this; or a method that disables rendering?

It's for a dumbed-down search engine that flips through a bunch of URLs looking for a particular character pattern.

I could use an iframe and then look at iframe.innerHTML but that slows things down and creates too much traffic as the browser loads ads and images.

The document sources are all over the web so AJAX is not on. PHP is a last resort.

5
  • So you want to do this entirely on the client-side? Commented Aug 27, 2012 at 14:48
  • Not possible, cross domain ajax and other methods of retrieving remote content from another domain is disabled on the client side for security reasons. Iframe.innerHTML is blocked as well. Commented Aug 27, 2012 at 14:50
  • @John: See the answer over here. Basically, Austin is correct. You're going to have trouble doing this without some server-side technology (like PHP, as mentioned) fetching the results for you. Commented Aug 27, 2012 at 14:52
  • Server-side javascript (node.js) or client-side? And when you say "I would like...", who are you referring to? Commented Aug 27, 2012 at 14:52
  • Thanks Cory. I could run AAMP on my PC's localhost but that's something else to keep updated. Not as bad as Adobe stuff though ... Commented Aug 27, 2012 at 15:39

1 Answer 1

2

The Same origin policy prevents this in the browser. It will only work if you fetch the html from the domain that your Javascript code is on.

PHP has a file_get_contents function that lets you do this.

Sign up to request clarification or add additional context in comments.

3 Comments

Odd that the browser permits loading an iframe with rendering but prohibits it without rendering./johnmck
@John Did you try accessing the innerHTML of the iframe if it has content from another domain in it? It shouldn't work.
Seems I'll have to dust off my AAMP installation and PHP the code. I wanted to flip through political cartoons (about 50/day) and highlight links that had fresh content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.