Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.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 我想使用不带iframe或object的外部url加载页面_Javascript_Jquery_Html_Jquery Ui_Jquery Plugins - Fatal编程技术网

Javascript 我想使用不带iframe或object的外部url加载页面

Javascript 我想使用不带iframe或object的外部url加载页面,javascript,jquery,html,jquery-ui,jquery-plugins,Javascript,Jquery,Html,Jquery Ui,Jquery Plugins,我想从div中的外部url加载页面,而不使用IFrame或object,我需要另一种方法。有人能帮我吗 它只在我使用Iframe或object时工作 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Te

我想从div中的外部url加载页面,而不使用IFrame或object,我需要另一种方法。有人能帮我吗

它只在我使用Iframe或object时工作

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Test page</title>
    <script src="https://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script>
      $(document).ready(function() { 
        $("#siteloader").load( "https://www.w3schools.com" );
      });
    </script>
  </head>
  <body>
    <div id="siteloader"></div>​        
  </body>
</html>

测试页
$(文档).ready(函数(){
$(“#siteloader”).load(“https://www.w3schools.com" );
});
​        

根据@DefyGravity在中的评论,出于安全目的,该网站(在本例中为
w3schools.com
需要允许您的网站访问内容

如果您可以访问将要访问的外部站点,则可以发送
来源:http://requestSite.com
标题至
http://w3schools.com
,但
w3schools.com
将必须发回
访问控制允许来源:http://requestSite.com
header,但这是我知道的唯一方法可能(仅当您有权访问要加载的其他站点的服务器时)


查看这个JSFIDLE的控制台输出,它支持我上面的理论:

也许你想尝试一下,或者

好吧,你已经为此使用了
.load()
。只要用
$(document.ready)(function(){your code})将这一行包装起来就可以了;
即使它不起作用-RegentI遗漏了word external。由于安全原因,您无法从另一个域加载页面。这是跨域请求。您需要启用CORS。由于浏览器安全限制,大多数“Ajax”请求受同源策略的约束;请求无法成功地从不同的域、子域、端口或协议检索数据。我们可以通过任何其他方式获取url并显示内容,而不使用iframe或object。是的,这就是我在@Jagadeesh向您指出的。如果您查看控制台输出(浏览器中的开发人员工具),您将看到出现XmlHttpRequest错误,因为未发送访问控制允许源标题。这些都不重要……我所知的其他人都并没有感谢您的帮助。