Connecting Tech Pros Worldwide Help | Site Map

document.write-ing some innerHTML to a new window

  #1  
Old August 17th, 2006, 12:35 PM
e271828
Guest
 
Posts: n/a
I've got a way to get all of the source HTML for a given page by line
and detect where certain attributes exist, and I would like to write
the line of HTML code I've been working on into a new window. Right
now, the code looks something like this


---


function validate() {

// gets the HTML source of the document and splits it by line.
var allLines = document.documentElement.innerHTML.split('/n');

for (n=0;n<allLines.length;n++) {

// looks for opening tags, looks for STYLE attribute.
var openingTag = allLines[n].match(/</gi);
var styleAttribute = allLines[n].match(/style/gi);

if (openingTag && styleAttribute) {

// gives the line number, (n+1) and the HTML source ofline that has an
opening tag and //STYLE attribute. This works (even if this code I
wrote in 2 minutes has errors)
alert((n+1) + allLines[n]);

//Instead of an alert box, I'd like to write it to a document in a new
window. Unfortunately this //writes the output of the HTML (as if it
were a visual fragment of the page), not the HTML //source as I would
like. The line number shows up fine, but no source.
var newwindow = window.open('',errorwindow,iforget);
newwindow.document.write((n+1) + allLines[n]);
document.close;
}}}


---


So, does anyone know why the HTML source would show in an alert box,
but not in a document.write? Thanks.

  #2  
Old August 17th, 2006, 01:35 PM
e271828
Guest
 
Posts: n/a

re: document.write-ing some innerHTML to a new window


The actual code is the first section of code below. It will properly
bring up an alert box with any line of source that has a tag with a
STYLE attribute, and the line number of that particular element. What
I need, though, is for that information to be written to a document in
a new window. I've included a version of what I need, in case anyone
can suggest how that can be done.


---
Brings up an alert box with the source and line number:

function linenumber() {

var allLineNumbers = document.documentElement.innerHTML.split("\n");

for (var n=0;n<allLineNumbers.length; n++) {

allTags1 = allLineNumbers[n].match(/<[a-z].*/gi);
allTags2 = allLineNumbers[n].match(/style.*/gi);

if(allTags1&&allTags2){
alert((n+1)+allLineNumbers[n]);
}}}


---
Brings up new window and writes one of the line numbers, but not the
source:

function linenumber() {

var allLineNumbers = document.documentElement.innerHTML.split("\n");

for (var n=0;n<allLineNumbers.length; n++) {

allTags1 = allLineNumbers[n].match(/<[a-z].*/gi);
allTags2 = allLineNumbers[n].match(/style.*/gi);

if(allTags1&&allTags2){

errwin =
window.open('','errorwindow','width=525,height=375 ,scrollbars=yes');
errwin.document.write(n +allLineNumbers[n]);
errwin.document.close();
}}}

---


Thanks.

  #3  
Old August 17th, 2006, 03:25 PM
Yanick
Guest
 
Posts: n/a

re: document.write-ing some innerHTML to a new window



function linenumber() {

var docHTML = document.documentElement.innerHTML;

// match any tag (group \1) with a style sttribute (group \2)
// we know it's a tag when it has an ending tag
// this regulare expression doesn't match tags like <br style="" />
// because it has no ending tag (</brwhich is not valid HTML)
var strMatches = docHTML.match( /<(.*)\s*(style=).*>.*<\/\1>/gi );

// we we have matches
// could also look for strMatches.length 0
if ( strMatches ) {
// loop through them all...
for ( var i=0; i<strMatches.length; i++ ) {
// get their index within the original string
var index = str.indexOf( strMatches[i] );

// here it is important to replace special tag characters by their
html equivalent
document.writeln( "Match at " + index + " = " +
strMatches[i].replace( /</g, '&lt;' ).replace( />/g, '&gt;' ) );
}

} else {

document.write( 'No match found !' );
}

</script>

</pre>

</body>
</html>


Hope this helps.

  #4  
Old August 17th, 2006, 03:25 PM
Yanick
Guest
 
Posts: n/a

re: document.write-ing some innerHTML to a new window


hmm... I must've woke up that wrong side of the bed this morning...
can't copy/paste right... Well, the general idea is there...

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Submit One Field of a Form to a New Window vunet.us@gmail.com answers 6 March 5th, 2007 03:15 PM
FAQ Topic - How do I open a new window with javascript? FAQ server answers 4 November 24th, 2006 12:45 AM
refering layer in new window news.versatel.de answers 6 July 23rd, 2005 04:03 PM
document.write Trevor Stapleton answers 3 July 20th, 2005 03:45 PM
Mouse shape after opening a new window and closing it Jawahar Rajan answers 2 July 20th, 2005 10:22 AM