doug s wrote:
How would I access the source of a webpage? I would like to get the source,
then use a regexp to find text on a webpage. For example, retrieving a
counter, or some other text that dynamically changes. I'm implementing this
for firefox.
right now, i have a web page opening that contains that info, but i would
rather have a pop up alert() that shows that info.
thanks for any help. and any code snippets would be great.
There are at least three ways of getting the text content of the document.
The standards-compliant method is to use document.body.t extContent, but
since it's DOM 3 it may not be widely supported beyond Mozilla/Firefox.
The IE-centric way is to use innerText as IE does not support textContent.
A third, reasonably cross-browser method is to use innerHTML and a
regular expression. But it's not a standard and different
implimentations may have small variations in how they've copied it from IE.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> blah </title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
function showText( el )
{
var txt;
if ( el.textContent ) {
txt = 'textContent\n' + el.textContent;
} else if ( el.innerText ){
txt = 'innerText\n' + el.innerText;
} else if ( el.innerHTML ) {
txt = 'innerHTML\n' + el.innerHTML.re place(/<\/?.[^\>]*>/g,'');
}
return txt;
}
</script>
</head>
<body >
<div onclick="alert( showText( document.body ));">
Here is <div>the <span> content. <b>Hi</b></span>
<br>Click me to see the content.
</div>
</div>
</body>
</html>
--
Rob