javascript 代码将通过 google chrome 中的网址栏从 www.example.com 启动,因此我无法使用 jquery。我的目标是当我在 www.example.com 中启动代码时,将 www.example.com/page.html 的完整 html 源代码传递给 javascript 中的变量。这可能吗?如果是这样怎么办?我知道要获取当前页面源,只需document.documentElement.outerHTML
但我不确定我该怎么做。我认为可以使用responseText
在以下代码中的某处:
http.send(params);
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","http://www.example.com/page.html",true);
xmlhttp.send();
data = ""
url = "http://www.example.com/page.html"
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4){
data = xhr.responseText
}
}
xhr.send();
function process(){
url = "http://www.example.com/page.html"
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4){
alert(xhr.responseText)
}
}
xhr.send();
}
这就是我从地址栏运行脚本的方式..我一直这样做..
我创建一个像这样的书签javascript:script=document.createElement('script');script.src='http://10.0.0.11/clear.js';document.getElementsByTagName('head')[0].appendChild(script); void(sss=1);
然后我在我的计算机上托管js文件..我使用analogx simpleserver...然后你可以为你的脚本使用完整的页面
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)