我已阅读并尝试了许多解决方案来向下滚动iframe,但这些解决方案都不适用于我。这是javascript函数,是由jquery.js完成的计时器回调。当输入文件被更改时,我重新生成页面(src =“pp_ContactRangesPanel.php?sc = terra& path = / var / www / html / java_clocks / terra / terra_aos_times& filter = N; #target”)并更新了iframe通过reload()。然后我尝试滚动到iframe中的name =“target”行,但它永远不会移动。在输入网页的顶部有一个“跳转到目标行”按钮,它跳转到目标行ok,所以我知道重新加载后标记就在那里。这是重新加载页面的javascript部分,应滚动到目标行。
// new mtime vs. last mtime test
if ($aPath[$currentFile][2] != $aPath[$currentFile][3]) {
$aPath[$currentFile][3] = $aPath[$currentFile][2];
// read in file again and re-populate mission table
var obj = document.getElementById($aPath[$currentFile][0]);
obj.contentWindow.location.reload();
var doc = (obj.contentDocument)? obj.contentDocument: obj.contentWindow.document;
var anchors = doc.getElementsByName('target');
// got target line?
if (0 < anchors.length)
{
doc.scrollTo(0, anchors[0].offsetTop);
}
}
有人头脑发热:
所以任何想法为什么不编写目标行?
答案 0 :(得分:0)
我找到了解决滚动问题的方法。我没有执行似乎不包含#target部分的obj.contentWindow.location.reload()命令,而是将src属性重置为自己的。由于原始的src字符串(例如“pp_ContactRangesPanel.php?sc = aqua&amp; path = / var / www / html / java_clocks / aqua / aqua_aos_times&amp; filter = N; #target”)在末尾包含“#target”字符串,iframe在重新生成页面时滚动到它。知道scrollTo命令的错误仍然会很好。
// read in file again and re-populate mission table
var obj = document.getElementById($aPath[$currentFile][0]);
// Note: the obj.contentWindow.location.reload(); way does not remember the #target
// part so I am resetting the src to the orginal src value thereby forcing it a reload by
// appending NULL to the end of the string. I could have gotten the string obj.src and
// used that, but this seems cleaner.
obj.src += '';