By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,520 Members | 1,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,520 IT Pros & Developers. It's quick & easy.

Walking the tree node on a page from another domain

Claus Mygind
P: 571
I have been working with the TreeWalker. I want to load a page from another domain. I got that working fine. I store 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
Expand|Select|Wrap|Line Numbers
  2. winRef ="" );
I have tried both of the following:
Expand|Select|Wrap|Line Numbers
  1.     var rootnode=winRef.document.getElementById("Form1")
  2.     var walker=winRef.document.createTreeWalker(rootnode, NodeFilter.SHOW_ELEMENT, myfilter, false)
Expand|Select|Wrap|Line Numbers
  1.     var rootnode=winRef.getElementById("Form1")
  2.     var walker=winRef.createTreeWalker(rootnode, NodeFilter.SHOW_ELEMENT, myfilter, false)
each time I get the error "Permission denied".

below is my tree walker code.

Expand|Select|Wrap|Line Numbers
  1.  function walkTheNodes()
  2.  {
  3.     //var rootnode=document.getElementById("Form1")
  4.     var rootnode=winRef.getElementById("Form1")
  5.     var walker=document.createTreeWalker(rootnode, NodeFilter.SHOW_ELEMENT, myfilter, false)
  8.     //Step through and alert all child nodes
  9.     while (walker.nextNode())
  10.     alert(walker.currentNode.tagName) 
  12.     var cHref = walker.currentNode;
  13.     var cChk  = walker.currentNode.href;
  15.     var i = walker.currentNode.href.indexOf("seek/log");
  17.     if ( i != -1 )
  18.     {
  19.         alert(walker.currentNode.href);
  20.     }else{
  21.         alert("Did not find");
  22.     }
  24.     //Go back to the first child node of the collection and alert it
  25.     walker.currentNode=rootnode //reset TreeWalker pointer to point to root node
  26. }
  28. myfilter=function(node){
  29. if ( node.tagName=="A") //filter out INPUT
  30. return NodeFilter.FILTER_ACCEPT
  31. else
  32. return NodeFilter.FILTER_SKIP
  33. }
Oct 31 '09 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 15k+
P: 16,027
Yes, this is not going to be possible, but you can serve the page from your domain to avoid cross-domain problems.
Nov 1 '09 #2

Claus Mygind
P: 571
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?
Nov 8 '09 #3

Expert Mod 15k+
P: 16,027
See this link for some ideas. Although it is geared towards Ajax, the article is still relevant.
Nov 8 '09 #4

Claus Mygind
P: 571
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.
Nov 9 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.