如何将网址加载到div标签中
问题描述:
我有一个<div id="content">
要加载url: http://vnexpress.net 内容
我的代码:
I have a <div id="content">
want to load url: http://vnexpress.net content into
my code:
<html>
<head>
<script type="text/javascript">
$(document).ready(function(){
$("#content").attr("src","http://vnexpress.net");
})
</script>
</head>
<body>
<div id="content"></div>
</body>
</html>
我不想使用iframe
I don't want to use Iframe
答
尝试 load()函数.
$('#content').load("http://vnexpress.net");
请注意,要使其正常工作,要加载的URL必须与调用它的页面位于同一域中,或启用.这涉及以最基本的形式发送其他HTTP标头:
Please not that for this to work, the URL to be loaded must either be on the same domain as the page that's calling it, or enable cross-origin HTTP requests ("Cross-Origin Resource Sharing", short CORS) on the server. This involves sending an additional HTTP header, in its most basic form:
Access-Control-Allow-Origin:*
允许来自任何地方的请求.
to allow requests from everywhere.