经过3天的研究和反复试验,我无法获取iframe及其内容来触发resize事件,以便调用我的resize函数.如果我使用...触发器("调整大小"); 要手动触发resize事件,我的调整大小函数被调用并起作用.iframe中加载http://localhost:81/curlExample/的页面与包含iframe的页面位于同一个域()上.最终,iframe中的页面将由php curl方法提供,但我想先让它工作.
*******更新********当我调整浏览器窗口大小导致iframe调整其大小时,如何触发调整大小事件?
谢谢您的帮助!
带有iframe的页面
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
function setResize()
{
window.alert("Hello");
var iframeRef = document.getElementById('displayframe');
$(iframeRef).on("resize", function(){
var xExp = 0;
window.alert("Resize event fired.");
});
}
$('#displayframe').load(function()
{
alert("Hello from iFrame. Load event fired.");
var myStallTime = setTimeout(setResize, 3000);
});
});
</script>
</head>
<body>
<p id="myP">Hello</p>
<iframe id="displayframe" src="http://localhost:81/curlExample/HelloIframe.xhtml" style="height:250px; width:100%;">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
iframe中的页面(HelloIframe.xhtml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TODO supply …Run Code Online (Sandbox Code Playgroud)