...

View Full Version : Using DOM to get at the contents of a modified frame



Norm White
11-19-2003, 07:21 PM
The application that I am trying to develop is a web-crawler written in JavaScript. The top module called JSBrowse.html defines two frames: an upper one called toppart, and a lower one called bottompart. Toppart.html in turn defines two frames: one called leftpart and one called rightpart. (I would have atached all 4 modules, but I don't know how to attach more than one module, so I chose rightpart.html.)

Leftpart shows the current www page that you have crawled to.

Rightpart contains a button that takes you to the next page in what will eventually be a pushdown list.

Bottompart scans each page for the presence of keyword, and also shows the dom structure of the document.

In rightpart I use this statement to update the URL of leftpart: parent.frames('leftpart').window.document.URL=document.form1.text1.value;

THE PROBLEM IS: The DOM tree that is displayed is the tree of my original html page (i.e., leftpart). What I want is the DOM tree of the current content.

I own 5 books on JavaScript including "HTML Black Book", "JavaScript: The Complete Reference", and 3 others, and I have not found the answer to my question.

I could sure use a clue, or ideas to solve this problem.

Thanks,
Sincerely

adios
11-19-2003, 07:26 PM
Not really enough to go on - but this is nasty:

parent.frames('leftpart').window.document.URL=document.form1.text1.value;

You're using parentheses as array element operators - OK in IE (VBScript convention) but nowhere else. document.URL is read-only. Try:

top.frames.leftpart.location=document.form1.text1.value;

Norm White
11-19-2003, 08:06 PM
I changed the statement to:
parent.frames.leftpart.location= . . .
It also works, but no differently from what I orignally had.
When I click the button, an error message comes up on that statement (either on the old or the new) which says "permission denied". However, if I click the back button and then click my "Next Page" button it fetches the next page in OK.

The more serious problem is getting the DOM structure of the replacement page. My DOM parsing code is:
<!--***********************Move HTML text into the bottompart frame-->
top.frames('bottompart').form2.analyze.value="";
var i,imax=40,k=0,origLength,delta="";
var currentElement = parent.frames('leftpart').window.document.documentElement;

i=imax;
origLength=parent.frames('leftpart').window.document.all.length;

<!--for (i=0;i<origLength;i++)-->
while (i-- > 0)
{
if (i==imax-1)
{
top.frames('bottompart').form2.analyze.value=currentElement.outerHTML+"\n";
}
top.frames('bottompart').form2.analyze.value=
top.frames('bottompart').form2.analyze.value+delta+
currentElement.nodeName+" "+
"nodeType="+currentElement.nodeType+" "+
"nodeValue="+currentElement.nodeValue+"\n";

if (k==0 && currentElement.hasChildNodes())
{
currentElement=currentElement.firstChild;
delta=delta+" ";
}
else
if (currentElement.nextSibling)
{
k=0;
currentElement=currentElement.nextSibling;
}
else
if (currentElement.parentNode)
{
currentElement=currentElement.parentNode;
delta=delta.substring(0,delta.length-5);
k=1;
}
else
break;
}

COBOLdinosaur
11-19-2003, 10:33 PM
You are trying to script cross-domain. That is a security violation. If you could modify code cross-domain, it would be a huge security hole.

Cd&



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum