js怎么获取iframe的DOM元素呢?百度上搜索方法尝试了多次,依然还是没有解决,有望大佬指点一下。我的代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Parent Page</title>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div style="margin:auto;">
<input type="button" value="调用子页面的方法"  onclick=javascrtpt:btnClick()>
</div>
<div style="margin:auto;">
<iframe style="width:1200px; height:600px;" id="childframe" allowfullscreen="true" allowtransparency="true" src="https://v.qq.com/x/cover/le1y6ytqnnd2ua2.html"></iframe>
</div> <script language="javascript" type="text/javascript"> function btnClick() {
//document.getElementById("childframe").contentWindow.childtest();
//var Video = document.querySelector("txpdiv.txp_video_container.txp_video_fit_cover > video:nth-child(1)")
console.log("test") var document.querySelector("html body div iframe").ownerDocument.querySelector('txpdiv.txp_autohide_progress txpdiv.txp_video_container video:nth-child(1)')
console.log(v)
}
</script></body>

解决方案 »

  1.   

    在开发者模式尝试下面的代码,报出异常var ifr = document.getElementById("childframe");
    var dom =  ifr.contentWindow.document
    异常代码Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
        at <anonymous>:1:29
    查询了下资料,说是跨域问题
    https://www.cnblogs.com/evaxtt/p/9585516.html 难道就没有解决方法了吗??
      

  2.   

    看到有人说可以用chrome浏览器的跨域功能,快捷方式后添加,试了下感觉还是不行。
    --disable-web-security --user-data-dir=