gpt4 book ai didi

javascript - 无法在本地文件中加载任何 iframe?

转载 作者:行者123 更新时间:2023-11-30 11:02:43 25 4
gpt4 key购买 nike

我创建了以下文件:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
iframe {
height: 500px;
width: 600px;
}
</style>
</head>
<body>
<iframe src="www.youtube.com">
</body>
</html>

我只是想将任何站点加载到 iframe 中,只是为了测试 iframe 的工作原理。但是无论我在 src 属性中放置什么 URL,当我在浏览器中打开这个文件时,我都会得到相同的结果:

enter image description here

iframe body 的内容变成了这样:

enter image description here

这似乎是一种通用的 chrome 错误。控制台中没有错误。这不是我尝试加载的域的安全措施。

这是怎么回事?

最佳答案

你好,临时用户名,

某些网站拒绝来自 iframe 的连接并不少见,youtube 就是其中之一。

我能够使用以下代码从 microcenter 加载页面:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<style>
iframe {
height: 1000px;
width: 1000px;
}
</style>
</head>
<body>
<iframe
src="https://www.microcenter.com/product/601585/970-evo-500gb-v-nand-m2-2280-pcie-nvme-30-x4-internal-solid-state-drive"
>
</body>
</html>

附言:在您提供的屏幕截图中,如果您将鼠标悬停在 iframe 上,如果我是正确的,它应该理想地显示“youtube.com 拒绝连接”。

编辑:我还应该注意,您通常必须包含完整的 url,http://或 https://

Edit2:由于有些人对为什么有些网站会阻止 iframe 有一些疑问,有关此方面的更多信息,请查看 https://ziplineinteractive.com/blog/how-to-prevent-a-website-from-being-loaded-in-an-iframe/ .这是一篇关于如何防止在 iframe 中加载您的网站及其原因的文章。

关于javascript - 无法在本地文件中加载任何 iframe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56978173/

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