我们在应用程序中使用帧。在一个框架中,滚动设置为"auto"。我试图基于一个小的条件来改变这个框架属性。下面是HTML和JavaScript:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=5">
</head>
<frameset>
<frame src="#" name="contentFR" id="contentFR" scrolling="Auto" noresize marginwidth="0" marginheight="0">
</frameset>
<script language="javascript">
var iFrm = document.getElementById("contentFR");
iFrm.setAttribute('scrolling', 'no');
</script>
</html>我正在使用IE 11,但我的应用程序只能在IE5兼容模式下运行。
发布于 2016-08-11 22:15:52
更新的方法:只需克隆节点。
// Proceed when the document has loaded
var timer = setInterval(function () {
// The document has loaded
if ( document.readyState === "complete" ) {
// Stop checking document load-state
clearInterval( timer );
// Get our frame, and create a clone of it
var frame = document.getElementById("contentFR");
var clone = frame.cloneNode(true);
// Update the scrolling on the clone
clone.setAttribute("scrolling", "no");
// Replace original frame with clone frame
frame.parentElement.replaceChild(clone, frame);
}
}, 10);有关为什么选择这条路线的更深层次的解释,请参见下文。
更改属性和/或属性不起作用,这让我感到困惑。当然,我只能在Windows 10上查看11,所以我不知道在早期构建的中是否会出现同样的问题。既然您说您的用户将在11中,我们可以放心地假设,如果我们遇到这个问题,他们也会。
我还发现,将<script>放在框架集中也是行不通的,所以我不得不将它放在<head>中(脚本只能放在<body>或<head>中,而且由于本文档中没有<body>,所以只能将它们放在<head>中)。因为头是先被解析/创建的,所以我们的框架元素不会及时从头中改变它。此外,由于我们使用的是IE5文档模式,所以我们不能仅仅监听document上的DOMContentLoaded事件。相反,我选择每10 as检查一次document.readyState值,直到它注册为完整为止。
最后,正如您已经发现的,简单地更新属性似乎不起作用。设置属性似乎也不起作用。奇怪的是,如果在执行操作后检查元素,这两个值实际上都会从Auto更改为No,但是更改没有反映在文档中。因此,我决定创建一个全新的框架,取代另一个框架。
这段代码让人感到非常、非常不正确。希望有人能参与进来,分享一种不需要经历极端处理的方法,比如从根本上复制一个元素,并将其中一个属性应用于另一个元素。在那之前,这个解决方案似乎是可行的。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=5">
<script type="text/javascript">
// Proceed when the document has loaded
var timer = setInterval(function () {
if ( document.readyState === "complete" ) {
// Stop checking document load-state
clearInterval( timer );
// Get our frame, and create a replacement
var frame = document.getElementById("contentFR");
var newFrame = document.createElement( "frame" );
// Copy all attributes over
var i = 0, attr;
for ( ; i < frame.attributes.length; i++ ) {
attr = frame.attributes[i];
// If we found a scrolling attribute, set it to 'no'
if ( attr.name === "scrolling" ) attr.value = "no";
// Apply old attribute to new frame
newFrame.setAttribute( attr.name, attr.value );
}
// Replace old frame with new frame
frame.parentElement.replaceChild( newFrame, frame );
// Null-out our variables
frame = i = attr = timer = null;
}
}, 10);
</script>
</head>
<frameset cols="50%, *">
<frame src="side.html">
<frame src="page.html" id="contentFR" scrolling="Auto" noresize marginWidth="0" marginHeight="0">
</frameset>
</html>https://stackoverflow.com/questions/38883184
复制相似问题