I have a website where ALL of my content pages open inside of an iframe.
One of the issue I am having, is when a visitor opens a 2nd page on my site, it opens at the same 'scroll position' as the previous page they were on.
I would like all of my pages to open at the top.
NOTE: I have spent days and hours searching on this site and other sites trying to find something that works. None of the solutions I have found have worked so far.
So... I decided to post my question and a very stripped down example of 3 pages to see if I can get some much needed help with this.
Any help or advice is appreciate.
Here is the 'index' (parent) page:
<!DOCTYPE html>
<html>
<head>
<style>
body{margin:0;}
.header{width:100%; height:60px; background-color:blue;}
.header a{vertical-align:middle; line-height:60px; font-family:Arial; font-size:12pt; color:#ffffff;}
#myiframe{width:100%; height:2000px;}
.footer{width:100%; height:60px; background-color:blue; margin-bottom:20px;}
.footer a{vertical-align:middle; line-height:60px; font-family:Arial; font-size:12pt; color:#ffffff;}
</style>
</head>
<body>
<div class="header"><a>This is the Header of the index (parent) page.</a></div>
<iframe id="myiframe" name="myiframe" src="1stPage.html"></iframe>
<div class="footer"><a>Footer</a></div>
</body>
</html>
Here is the 1st 'content' page (including the last failed scroll code):
<!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>
And finally... the 2nd 'content' page (also including the last failed scroll code):
<!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 onload事件中执行此操作,如下所示:
<iframe id="myiframe" name="myiframe" src="1stPage.html" onload="scroll(0,0);"></iframe>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.