Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2003
    Location
    Virginia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using DOM to get at the contents of a modified frame

    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

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    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;

  • #3
    New to the CF scene
    Join Date
    Nov 2003
    Location
    Virginia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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;
    }

  • #4
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    396
    Thanks
    2
    Thanked 30 Times in 30 Posts
    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&
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •