簡體   English   中英

在頂部加載我的所有頁面

[英]Load All Of My Pages At Top

我有一個網站,所有內容頁面都在iframe中打開。

我遇到的問題之一是,當訪​​問者在我的網站上打開第二頁時,它以與他們上一頁相同的“滾動位置”打開。

我希望所有頁面都在頂部打開。

注意:我花了數天和數小時在此站點和其他站點上進行搜索,試圖找到可行的方法。 到目前為止,我發現的所有解決方案都沒有奏效。

所以...我決定發布我的問題和一個精簡的示例(共3頁),以查看是否可以得到一些急需的幫助。

任何幫助或建議,不勝感激。

這是“索引”(父級)頁面:

    <!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>

這是第一個“內容”頁面(包括最后一個失敗的滾動代碼):

    <!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 onload事件中執行此操作,如下所示:

<iframe id="myiframe" name="myiframe" src="1stPage.html" onload="scroll(0,0);"></iframe>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM