// <div><iframe name="frames" id="frames" src="demo.html" height="140"></iframe></div>
iframe 页面:
<html> <head> <title>页面内的iframe页面</title> </head> <body> <div class="inneriftame"><input id="inputid" type="text" value="123456" /></div> </body> </html>
获取iframe的页面input值
<script type="text/javascript"> function getiframevalue(){ var isIframe = document.getElementById("frames").document; if(isIframe ==undefined){/*chrome safari浏览器获取iframe*/ isIframe = document.getElementById("frames").contentWindow.document.getElementById("xx").value;/*操作iframe的DOM*/ }else{/*IE浏览器获取*/ isIframe = document.frames["frames"].document.getElementById("xx").value;/*操作iframe的DOM元素*/ } } </script>
注:
SecurityError: Blocked a frame with origin "null" from accessing a cross-origin frame错误是在本地跑的时候出现的;
如果放到服务器是正常的。