gpt4 book ai didi

javascript - 将网页链接加载到 div 或 iframe

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:21 26 4
gpt4 key购买 nike

这可能是一个普遍的问题。我看到了几个关于这个问题的答案。

  1. 使用 jquery 加载
  2. 使用 iframe

我都试过了,但加载不方便。这是为了加载 google.com 而无法正常工作。

<html>
<head>
<title>hhh</title>
<script src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#content").attr("src","http://www.google.lk/");
})
</script>
</head>
<body>
<iframe id="content" src="about:blank"></iframe>
</body>
</html>

但是当我尝试加载 w3schools.com 时,它会加载到 iframe 中

<html>
<head>
<title>hhh</title>
<script src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#content").attr("src","http://w3schools.com/");
})
</script>
</head>
<body>
<iframe id="content" src="about:blank"></iframe>
</body>
</html>

当使用 jQuery 加载时,它也不起作用。

<html>
<head>
<script src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#content").load("src","http://www.google.com/");
})
</script>
</head>
<body>
<div id="content" src="about:blank"></div>
</body>
</html>

并且在 Firebug 栏中显示为“GET http://www.google.com 302 Found 291ms

有些人帮我摆脱了这个。

最佳答案

使用jquery加载显示div中的内容。 div 没有 src

影响 iframesrc 告诉您的浏览器获取内容并将其显示在 iframe 中。

load() 的正确语法是:

<div id="content"></div>

$("#content").load("page.php");

顺便说一句,google.com 不喜欢从其他网站加载,因此您最好使用其他示例。

关于javascript - 将网页链接加载到 div 或 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14223408/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com