iframe获取焦点的问题、获取iframe src、打开新窗口window.open()

来源:互联网 发布:origin软件怎么安装 编辑:程序博客网 时间:2024/06/05 04:41

<iframe id="embed"  frameborder="no"  name="abc" border="0"  src="www.lingpic.com"  style="width:100%; color:#000;" mozallowfullscreen webkitallowfullscreen allowfullscreen></iframe>


1、先获取iframe再加focus()函数

document.getElementById('embed').focus();


2、在iframe框架里面点击元素让iframe获取焦点

如果www.lingpic.com里面有个<div id="box"></div> 的元素 那我们点击box让iframe获取焦点。例:

document.getElementById('box').onclick = function(){

       var aFrame = parent.frames;      //获取frames 是个类似数组

       aFrame[0].focus();

}


3、在iframe里获取iframe的src

document.getElementById('box').onclick = function(){

       var aFrame = parent.frames;      //获取frames 是个类似数组

      var src = aFrame[0].location.href;

      //打开新窗口

      window.open (src, 'newwindow', 'height=700, width=1000, top=50,left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')

}

打开新窗口 newwindow名称只有不同的时候才能打开多个新窗口





0 0
原创粉丝点击