Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading raw HTML with javascript

Status
Not open for further replies.

jamesp81

Programmer
Mar 3, 2006
19
US
Does anyone know how, or if it is possible, for a javascript to read the raw HTML of the page it's on. If so, does anyone know how to go about this?
 
Let me ask one more quick question: is there a way to designate a certain section of HTML code that you want to read?

Here's my situation, so you can understand it a bit better: my company has a large website and on each page we have a information arranged in basically 3 columns. The leftmost and rightmost columns are information columns that appear on all pages. The center, and largest, column is the main body which contains the primary information for that page. What I'd like to do is read the main body HTML only, strip the table tags out of it, and spit it back out as a temp file on the user's machine. The problem is that I can't think of any way to uniqely identify this main body from all the other HTML for the script to catch it.

I suppose I could go through and use the 'name=xxxx' tag on the paragraphs the main body is in, but I just wanted to check and see if there was an easier way to do that before I went off and started doing the keyboard work on that.
 
Instead of this:

Code:
document.getElementsByTagName('body')[0]

you can use a reference to any element you like. Basically, it's the innerHTML property you are after.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
If each "middle" column had an ID or a unique class on it... then you could do it easily using getElementsById() (and optionally check the class).

If each page has the same structure, you could walk the DOM nodes for the body and grab the Xth <div> or whatever for parsing.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top