Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取浏览器窗口中的文本的步骤_Javascript_Jquery_Html_Cross Domain - Fatal编程技术网

Javascript 获取浏览器窗口中的文本的步骤

Javascript 获取浏览器窗口中的文本的步骤,javascript,jquery,html,cross-domain,Javascript,Jquery,Html,Cross Domain,我想在使用以下代码打开的窗口中显示文本 var yy = window.open("http://www.vignanuniversity.org/"); 现在我想在我使用的窗口中显示文本 var responseText = yy.html(); 我在chrome控制台中得到的错误如下 Protocols, domains, and ports must match. 因此,我使用跨域,然后如何获得问题的解决方案。无法访问其他网页的窗口内容。但是,

我想在使用以下代码打开的窗口中显示文本

  var yy = window.open("http://www.vignanuniversity.org/");
现在我想在我使用的窗口中显示文本

            var responseText = yy.html();
我在chrome控制台中得到的错误如下

      Protocols, domains, and ports must match.

因此,我使用跨域,然后如何获得问题的解决方案。

无法访问其他网页的窗口内容。但是,您可以让javascript在后端向您的服务器发出请求,为您发出请求

Javascript

//Gets the contents of the web page using the backend server
getContents("http://www.vignanuniversity.org/", function(contents, responseCode){
    alert("Page received with status: " responseCode);
    alert(contents);
});

//Takes the URL as page and a function to handle the result.
//retFunc has one parameter, which is the response
function getContents(page, retFunc){
    var myServer = "/php/getRemote.php";
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4){
            retFunc(xmlhttp.responseText, xmlhttp.status);
        }
    }
    xmlhttp.open("GET", myServer + "?url=" + page);
    xmlhttp.send();
}
PHP

//Location: /php/getRemote.php
$url = $_GET["url"];
echo file_get_contents($url);

这将允许您有效地获取网站的内容。您将无法访问修改后的内容

您可以使用服务器端脚本之类的东西,比如php,然后调用脚本并获取其响应。否则,唯一的其他方法是,如果外部域使用消息传递api并设置了一个命令来返回某些消息上的页面html,我怀疑任何站点都不会这样做。