请大家帮忙,再次请教,在父页面内通过js脚本控制iframe的滚轴事件,谢谢大家了。 楼主这样MS有点杀鸡用牛刀,也许真的没有考虑清楚,何必这样呢,你所谓的控件输出出来的iframe,没有滚轴?如果这样的话,你在父窗口再来控制iframe,有点不太可能!换个思路试试吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参见:http://www.v-ec.com/jslib/【Iframe滚动兼容】部分! 控件输出来的iframe是有滚动条的,但是我把iframe的长和宽都设的很大,所以iframe撑开了,滚动条就没了。 iframe自适应?<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>iframe</title></head><body><script type="text/javascript">function SetCwinHeight(){ var bobo=document.getElementById("bobo"); //iframe id if (document.getElementById){ if (bobo && !window.opera){ if (bobo.contentDocument && bobo.contentDocument.body.offsetHeight){ bobo.height = bobo.contentDocument.body.offsetHeight; }else if(bobo.Document && bobo.Document.body.scrollHeight){ bobo.height = bobo.Document.body.scrollHeight; } } }}</script><iframe width="100%" id="bobo" onload="Javascript:SetCwinHeight()" height="1" frameborder="0" src="IFrame_myPage.aspx"></iframe>其实很简单</body></html> 我现在在父页面找不到iframe的滚轴事件,是因为这个iframe是动态生成的吗 动态生成的?那也应该有id吧? 不会动态生成的就找不到吧?无论如何生成,在客户端还是一样的html代码啊! 谢谢xiaojing7的帮忙,我的那个iframe是别的控件生成出来的,引用的时候不能直接写 <iframe>...</iframe>就是<iframe width="100%" id="bobo" onload="Javascript:SetCwinHeight()" height="1" frameborder="0" src="IFrame_myPage.aspx"></iframe>这句在父页面上是没有的要等到iframe生成出来后给iframe加上onload事件,怎么加呢,谢谢。 <iframe width="100%" id="bobo" onload="Javascript:SetCwinHeight()" height="1" frameborder="0" src="IFrame_myPage.aspx"> </iframe>这句也是动态生成出来的 那就控制,生成结束后,然后var obj = document.getElementById("bobo");obj.setAttribute("onclick", "Javascript:SetCwinHeight()"); 代码加上了,但是点击 iframe 没有反应,是不是iframe的onclick事件没有加上呢 你这个方法加在什么地方了?确保你的ifream已经生成了? if(document.readyState == "complete") { obj.setAttribute("onclick", "Javascript:SetCwinHeight()"); }这样加的 汗!我写错方法了。怎么能用onclick呢!应该是onload不好意思!你用onload再试下,刚没看清楚,写错了! bobo.height = bobo.contentDocument.body.offsetHeight;这句使iframe在父页面上出现滚动条吧,我不能让iframe在父页面上出现滚动条 不让iframe出现滚动条,父页面上有滚动条,鼠标在iframe的区域上滚动时等于用的是父页面的滚动条相当于 iframe.滚轴事件 = 父页面.滚轴事件 好的,谢谢,能留个msn吗 CSS的解释 谁能推荐个JAVASCRIPT视频教程 IE text 中如何实现 Ctrl+C 调用自己的js函数 如何删除用innerHTML创建的超链接。 请问这个JS用什么方法压缩的? 不好意思!在这里问个asp问题?谁叫这里人气旺呢! 如何得到浏览器的宽度 如何锁死溜览器的关闭按钮? 一个简单正则表达式的问题 请问有无现成的键码表,或者区分字符键和功能键的方法?(必给分) 100分求人看一个<javascript高级程序设计>>书的上错误!!!!! 页面中怎么加入swf格式的?
http://www.v-ec.com/jslib/【Iframe滚动兼容】部分!
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>iframe</title>
</head>
<body>
<script type="text/javascript">
function SetCwinHeight(){
var bobo=document.getElementById("bobo"); //iframe id
if (document.getElementById){
if (bobo && !window.opera){
if (bobo.contentDocument && bobo.contentDocument.body.offsetHeight){
bobo.height = bobo.contentDocument.body.offsetHeight;
}else if(bobo.Document && bobo.Document.body.scrollHeight){
bobo.height = bobo.Document.body.scrollHeight;
}
}
}
}
</script>
<iframe width="100%" id="bobo" onload="Javascript:SetCwinHeight()" height="1" frameborder="0" src="IFrame_myPage.aspx"></iframe>
其实很简单</body>
</html>
那也应该有id吧? 不会动态生成的就找不到吧?
无论如何生成,在客户端还是一样的html代码啊!
就是<iframe width="100%" id="bobo" onload="Javascript:SetCwinHeight()" height="1" frameborder="0" src="IFrame_myPage.aspx"></iframe>
这句在父页面上是没有的要等到iframe生成出来后给iframe加上onload事件,怎么加呢,谢谢。
然后
var obj = document.getElementById("bobo");
obj.setAttribute("onclick", "Javascript:SetCwinHeight()");
确保你的ifream已经生成了?
{
obj.setAttribute("onclick", "Javascript:SetCwinHeight()");
}这样加的
应该是onload不好意思!你用onload再试下,刚没看清楚,写错了!
这句使iframe在父页面上出现滚动条吧,我不能让iframe在父页面上出现滚动条
相当于 iframe.滚轴事件 = 父页面.滚轴事件