Javascript 在顶部加载我的所有页面
我有一个网站,我的所有内容页都在iframe中打开 我遇到的一个问题是,当访问者在我的网站上打开第二个页面时,它会在与上一个页面相同的“滚动位置”打开 我希望我所有的页面都在顶部打开 注意:我花了数天和数小时在这个网站和其他网站上搜索,试图找到一些有用的东西。到目前为止,我找到的解决方案都没有奏效 所以。。。我决定发布我的问题和一个3页的非常精简的例子,看看我是否能在这方面得到一些急需的帮助 任何帮助或建议都将不胜感激 以下是“索引”(父级)页面:Javascript 在顶部加载我的所有页面,javascript,jquery,html,scroll,scrolltop,Javascript,Jquery,Html,Scroll,Scrolltop,我有一个网站,我的所有内容页都在iframe中打开 我遇到的一个问题是,当访问者在我的网站上打开第二个页面时,它会在与上一个页面相同的“滚动位置”打开 我希望我所有的页面都在顶部打开 注意:我花了数天和数小时在这个网站和其他网站上搜索,试图找到一些有用的东西。到目前为止,我找到的解决方案都没有奏效 所以。。。我决定发布我的问题和一个3页的非常精简的例子,看看我是否能在这方面得到一些急需的帮助 任何帮助或建议都将不胜感激 以下是“索引”(父级)页面: 正文{页边距:0;} .header{宽度:
正文{页边距:0;}
.header{宽度:100%;高度:60px;背景色:蓝色;}
.header a{垂直对齐:中间;行高:60px;字体系列:Arial;字体大小:12pt;颜色:#ffffff;}
#myiframe{宽度:100%;高度:2000px;}
.footer{宽度:100%;高度:60px;背景色:蓝色;页边距底部:20px;}
.footer a{垂直对齐:中间;行高:60px;字体系列:Arial;字体大小:12pt;颜色:#ffffff;}
这是iframe中的第一页(…这是“页面位置”、“底部”或“X”)。
最后。。。第二个“内容”页面(还包括上次失败的滚动代码):
正文{页边距:0;}
.text{字体系列:Arial;字体大小:12pt;}
.link{页边距顶端:1900px;}
$(文档).ready(函数(){
$('html,body')。滚动顶部(0);
$(窗口).on('load',function(){
setTimeout(函数(){$('html,body').scrollTop(0);},0);
});
});
这是iframe中的第2页(…这是“页面位置”、“顶部”或“0”)。
请向下滚动至第2页的链接。
这是iframe中的第二页(…这是“页面位置”、“底部”或“X”)。
您可以在iFrameonload事件中执行此操作,如下所示:
<iframe id="myiframe" name="myiframe" src="1stPage.html" onload="scroll(0,0);"></iframe>
谢谢!那很有魅力!现在,我只需要弄清楚,当我在其他网站上共享指向我的页面的链接时,如何让页面与其父页面一起打开。
<!DOCTYPE html>
<html>
<head>
<style>
body{margin:0;}
.text{font-family:Arial; font-size:12pt;}
.link{margin-top:1900px;}
</style>
<script>
$(document).ready(function(){
$('html, body').scrollTop(0);
$(window).on('load', function() {
setTimeout(function(){ $('html, body').scrollTop(0);}, 0);
});
});
</script>
</head>
<body>
<div class="text">This is the 1st page in iframe (..and this is 'page postition' "Top" or "0").</div>
<div class="text">Please scroll down to the link to 2nd page.</div>
<div class="link"><a class="text" href="2ndPage.html" target="myiframe">Click here to go to 2nd Page</a></div><br>
<div class="text">This is the 1st page in iframe (..and this is 'page postition' "Bottom" or "X").</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body{margin:0;}
.text{font-family:Arial; font-size:12pt;}
.link{margin-top:1900px;}
</style>
<script>
$(document).ready(function(){
$('html, body').scrollTop(0);
$(window).on('load', function() {
setTimeout(function(){ $('html, body').scrollTop(0);}, 0);
});
});
</script>
</head>
<body>
<div class="text">This is the 2nd page in iframe (..and this is 'page postition' "Top" or "0").</div>
<div class="text">Please scroll down to the link to 2nd page.</div>
<div class="link"><a class="text" href="1stPage.html" target="myiframe">Click here to go back to the 1st Page</a></div><br>
<div class="text">This is the 2nd page in iframe (..and this is 'page postition' "Bottom" or "X").</div>
</body>
</html>
<iframe id="myiframe" name="myiframe" src="1stPage.html" onload="scroll(0,0);"></iframe>