为什么我的 jquery 不接受这个 iframe 的那个 类?
Why my jquery don't take that classes of this iframe?
我正在尝试获取名称为“titular_portada”的所有 类。
有很多,但由于某种原因不起作用:
<!DOCTYPE html>
<html lang="es">
<head>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<iframe src="https://vandal.elespanol.com" id="iframe" width="100%" height="100%"></iframe>
<script src="js/jquery-3.6.0.js"></script>
</body>
</html>
$(window).on("load", function() {
$("#iframe > .titulo_portada").each((i, el) => {
console.log(el);
});
});
$(window).on("load", function() {
var iframe = document.getElementById("iframe");
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
$(".titulo_portada",$(iframeDocument)).each((i, el) => {
console.log(el);
});
});
它应该可以工作,但是 jsfiddle 在 https://jsfiddle.net/NickU/65dxzg3s/9/
显示错误“未捕获的安全错误:阻止了来源为“https://fiddle.jshell.net”的框架访问跨域框架。”
我正在尝试获取名称为“titular_portada”的所有 类。
有很多,但由于某种原因不起作用:
<!DOCTYPE html>
<html lang="es">
<head>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<iframe src="https://vandal.elespanol.com" id="iframe" width="100%" height="100%"></iframe>
<script src="js/jquery-3.6.0.js"></script>
</body>
</html>
$(window).on("load", function() {
$("#iframe > .titulo_portada").each((i, el) => {
console.log(el);
});
});
$(window).on("load", function() {
var iframe = document.getElementById("iframe");
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
$(".titulo_portada",$(iframeDocument)).each((i, el) => {
console.log(el);
});
});
它应该可以工作,但是 jsfiddle 在 https://jsfiddle.net/NickU/65dxzg3s/9/ 显示错误“未捕获的安全错误:阻止了来源为“https://fiddle.jshell.net”的框架访问跨域框架。”