【发布时间】:2018-04-22 03:52:32
【问题描述】:
我正在开发一个网站,该网站要求用户登录第三方网站,该网站在 iframe 中显示在我的网站上。我正在尝试使用 jQuery 提取该网站的 html 代码,但它并没有真正起作用。这是我的代码。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Iframe</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
console.log($("#iframe").contents().find("body"));
});
</script>
</head>
<body>
<iframe src="https://www.google.com"></iframe>
</body>
</html>
我在示例中使用的是 google,但我使用的是不同的网站。我得到的结果是 - w.fn.init [prevObject: w.fn.init(0)] - 但我找不到 html。有谁知道怎么做吗?
【问题讨论】:
-
由于“同源策略”,您无法访问跨域 iframe。这是为了防止安全漏洞
-
看看这个question的答案
标签: javascript jquery html iframe