Walking the tree node on a page from another domain

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    Walking the tree node on a page from another domain

    I have been working with the TreeWalker. I want to load a page from another domain. I got that working fine. I store window.open() object in a global variable winRef.

    Then I would like to walk the nodes and find an anchor that contains "seek/log" in it's href attribute.

    Can that be done or is that a security violation and not permitted?

    I load the winRef variable like this
    Code:
        
    winRef = window.open("http://www.otherSite.com" );
    I have tried both of the following:
    Code:
    	var rootnode=winRef.document.getElementById("Form1")
    	var walker=winRef.document.createTreeWalker(rootnode, NodeFilter.SHOW_ELEMENT, myfilter, false)
    and
    Code:
    	var rootnode=winRef.getElementById("Form1")
    	var walker=winRef.createTreeWalker(rootnode, NodeFilter.SHOW_ELEMENT, myfilter, false)
    each time I get the error "Permission denied".


    below is my tree walker code.


    Code:
     function walkTheNodes()
     {
    	//var rootnode=document.getElementById("Form1")
    	var rootnode=winRef.getElementById("Form1")
    	var walker=document.createTreeWalker(rootnode, NodeFilter.SHOW_ELEMENT, myfilter, false)
    
    
    	//Step through and alert all child nodes
    	while (walker.nextNode())
    	alert(walker.currentNode.tagName) 
    
    	var cHref = walker.currentNode;
    	var cChk  = walker.currentNode.href;
    
    	var i = walker.currentNode.href.indexOf("seek/log");
    
    	if ( i != -1 )
    	{
    		alert(walker.currentNode.href);
    	}else{
    		alert("Did not find");
    	}
    
    	//Go back to the first child node of the collection and alert it
    	walker.currentNode=rootnode //reset TreeWalker pointer to point to root node
    }
    
    myfilter=function(node){
    if ( node.tagName=="A") //filter out INPUT
    return NodeFilter.FILTER_ACCEPT
    else
    return NodeFilter.FILTER_SKIP
    }
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Yes, this is not going to be possible, but you can serve the page from your domain to avoid cross-domain problems.

    Comment

    • Claus Mygind
      Contributor
      • Mar 2008
      • 571

      #3
      Ok so how do I capture the page from the domain that is not mine and re-load it from my domain as you suggest?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        See this link for some ideas. Although it is geared towards Ajax, the article is still relevant.

        Comment

        • Claus Mygind
          Contributor
          • Mar 2008
          • 571

          #5
          Thank you very much for the link. I have also read up on the proxy server idea. I will play around with that and post any success story if I have one. Opening up a proxy may be more of a security problem than I want to deal with to save one click on the mouse. But at least I can see how it is done.

          Comment

          Working...