在iframe中获取元素的xpath位置(来自我的域的iframe)

我有两个代码,我尝试以某种方式连接这两个代码。 在代码中也是获取xpath位置的函数,但是如何在iframe上使用它。 $(#iframeID) ….以及将getXpath函数的结果写入焦点字段的函数。 首先我加载一些URL我试图使用getXpath位置函数并将结果写入焦点的字段但它不起作用。

这是我用来获取内容的一些URL地址并在我的域中的iframe中显示的代码(因此我可以获得XPath因为iframe在我的域中),然后使用getXpath函数在焦点字段中写入结果:

 <?php error_reporting(E_ALL ^ E_NOTICE); $url = $_GET['url']; if( ! empty($url)) { $data = file_get_contents($url); $data = str_replace('', '', $data); $data = preg_replace('#(.*?)#is', '', $data); $data = preg_replace('##is', '', $data); $data .= '   $("div").each(function(i){ if($(this).css("position") == "fixed") $(this).css("display", "none"); });  ' ; die($data); } ?> 

这是HTML / JavaScript:

      AdriaMart  //function for xpath location  function getXPath(node, path) { path = path || []; if(node.parentNode) { path = getXPath(node.parentNode, path); } if(node.previousSibling) { var count = 1; var sibling = node.previousSibling do { if(sibling.nodeType == 1 && sibling.nodeName == node.nodeName) {count++;} sibling = sibling.previousSibling; } while(sibling); if(count == 1) {count = null;} } else if(node.nextSibling) { var sibling = node.nextSibling; do { if(sibling.nodeType == 1 && sibling.nodeName == node.nodeName) { var count = 1; sibling = null; } else { var count = null; sibling = sibling.previousSibling; } } while(sibling); } if(node.nodeType == 1) { path.push(node.nodeName.toLowerCase() + (node.id ? "[@id='"+node.id+"']" : count > 0 ? "["+count+"]" : '')); } return path; };  //function to get xpath location and write in textfield in focus  $(document).ready(function () { var selectedtextbox; $('input[name="myinput"]').focus(function(){selectedtextbox=$(this);}); $('p, li, a, href').click(function () { var xpath = getXPath(this); selectedtextbox.val(xpath) }); });            document.getElementById('iframe_button').onclick = function () { document.getElementById('iframe').src = '?url=' + document.getElementById('iframe_url').value; };   //Textfields for xpath location to write inside them