簡體   English   中英

我如何將用戶從另一個HTML頁面重定向到HTML頁面上的“部分”?

[英]How can i redirect the user to a 'section' on an html page from another html page?

  1. 我有一個主要網頁-index.html,其中包含“ #features”部分。
  2. 我在另一個網頁subpage.html上有一個后退按鈕,它將用戶重定向到index.html頁面(我使用過onclick =“ document.location = index.html”將用戶重定向到index.html頁面)

當用戶單擊subpage.html頁面上的后退按鈕時,我想將用戶重定向到index.html頁面上的“ #features”部分。 我怎樣才能做到這一點?

您可以通過內部頁面錨來實現。 嘗試這個:

在subpage.html中

window.location.href= "index.html#features";

在index.html中

<a id="features">row 15 data here.</a>

在這里工作

這就是我解決問題的方式。 只需將按鈕包裝上帶有href="/index.html#feature" a標簽即可。 如果兩個頁面都在同一目錄中,請使用href="./index.html#feature"

在javascript中使用scrollIntoView函數。 此處查閱文檔。

暫無
暫無

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

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