如何将网址加载到div标签中 [英] how to load url into div tag

查看:188
本文介绍了如何将网址加载到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.

这篇关于如何将网址加载到div标签中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆