Php 单击iframe上的HTML元素
可能重复:Php 单击iframe上的HTML元素,php,jquery,html,iframe,xpath,Php,Jquery,Html,Iframe,Xpath,可能重复: 我有一个javascript函数来获取xpath作为结果(getXPath),下面是代码。另外,我在iframe中有一个外部站点,但当我使用代理时,我会向他展示(代码如下)。当我单击iframe中的某个元素但不起作用时,我有一个jquery函数来显示xpath。问题是: 代码: 阿德里亚马特 //用于xpath位置的函数 函数getXPath(节点,路径){ 路径=路径| |[]; if(node.parentNode){ path=getXPath(node.parentNod
我有一个javascript函数来获取xpath作为结果(getXPath),下面是代码。另外,我在iframe中有一个外部站点,但当我使用代理时,我会向他展示(代码如下)。当我单击iframe中的某个元素但不起作用时,我有一个jquery函数来显示xpath。问题是: 代码:
阿德里亚马特
//用于xpath位置的函数
函数getXPath(节点,路径){
路径=路径| |[];
if(node.parentNode){
path=getXPath(node.parentNode,path);
}
if(节点上一个同级){
var计数=1;
var sibling=node.previousSibling
做{
如果(sibling.nodeType==1&&sibling.nodeName==node.nodeName){count++;}
兄弟姐妹=兄弟姐妹。以前的兄弟姐妹;
}而(兄弟姐妹);
如果(count==1){count=null;}
}else if(node.nextSibling){
var sibling=node.nextSibling;
做{
if(sibling.nodeType==1&&sibling.nodeName==node.nodeName){
var计数=1;
同级=空;
}否则{
var计数=null;
兄弟姐妹=兄弟姐妹。以前的兄弟姐妹;
}
}而(兄弟姐妹);
}
if(node.nodeType==1){
path.push(node.nodeName.toLowerCase()+(node.id?[@id=”“+node.id+”]”]:计数>0?[“+count+”]:”);
}
返回路径;
};
//函数获取xpath位置并写入焦点中的textfield
***
$('#iframe').ready(函数(){
var选择文本框;
$('input[name=“myinput”]”)。焦点(function(){selectedtextbox=$(this);});
$('div,p,li,a,href')。单击(函数(){
var xpath=getXPath(this);
selectedtextbox.val(xpath)
});
});
***
document.getElementById('iframe_按钮')。onclick=function(){
document.getElementById('iframe').src='?url='+document.getElementById('iframe\u url').value;
};
//要在其中写入的xpath位置的文本字段
***
$('#iframe').ready(函数(){
var选择文本框;
$('input[name=“myinput”]”)。焦点(function(){selectedtextbox=$(this);});
$('div,p,li,a,href')。单击(函数(){
var xpath=getXPath(this);
selectedtextbox.val(xpath)
});
});
***
有三个问题
问题是jquery代码高于$(#iframe')。就绪。。。这里的错误在哪里!!!
<?php
error_reporting(E_ALL ^ E_NOTICE);
$url = $_GET['url'];
if( ! empty($url))
{
$data = file_get_contents($url);
$data = str_replace('<head>', '<head><base href="'.$url.'" /></base>', $data);
$data = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $data);
$data = preg_replace('#<iframe(.*?)></iframe>#is', '', $data);
$data .=
'
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$("div").each(function(i){
if($(this).css("position") == "fixed") $(this).css("display", "none");
});
</script>
'
;
die($data);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="Webarto" />
<title>AdriaMart</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
//function for xpath location
<script type="text/javascript">
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;
};
</script>
//function to get xpath location and write in textfield in focus
***<script>
$('#iframe').ready(function () {
var selectedtextbox;
$('input[name="myinput"]').focus(function(){selectedtextbox=$(this);});
$('div, p, li, a, href').click(function () {
var xpath = getXPath(this);
selectedtextbox.val(xpath)
});
});
</script>***
<style type="text/css">
<!--
iframe{width:100%;height:400px;}
-->
</style>
</head>
<body>
<!-- ... -->
<input id="iframe_url" name="" type="text" />
<input id="iframe_button" name="" type="button" />
<iframe id="iframe" src="?url=http://kupime.com"></iframe>
<script type="text/javascript">
document.getElementById('iframe_button').onclick = function () {
document.getElementById('iframe').src = '?url=' + document.getElementById('iframe_url').value;
};
</script>
<!-- ... -->
//Textfields for xpath location to write inside them
<input id="" name="myinput" type="text" value="">
<input id="" name="myinput" type="text" value="">
<input id="" name="myinput" type="text" value="">
</body>
</html>
$('#iframe').ready(function () {
var selectedtextbox;
$('input[name="myinput"]').focus(function(){selectedtextbox=$(this);});
$('div, p, li, a, href').click(function () {
var xpath = getXPath(this);
selectedtextbox.val(xpath)
});
});
</script>***
//wait for ready in the current document to have access to #iframe
$(function()
{
$('#iframe')
//observe the load-event of the iframe-element
.on('load',
function ()
{
//set a default-input to avoid errors
var selectedtextbox=$('input[name="myinput"]:eq(0)');
$('input[name="myinput"]')
.focus(function(){selectedtextbox=$(this);});
//Note the 2nd argument here,
//it sets the contextof $() to the document inside the iframe
$('div, p, li, a, href',
this.contentWindow.document)
.click(function ()
{
var xpath = getXPath(this);
selectedtextbox.val(xpath)
});
});
});