簡體   English   中英

使用javascript重定向到html頁面

[英]redirect to html page using javascript

我有2個html頁面,第一個是登錄頁面,第二個,當我登錄i重定向到主頁面時,必須必須在加載時執行,只有在登錄此方法必須調用后首次加載頁面。 當我重新加載或刷新此方法時再次調用。

1- can i refresh the page without calling the onload method? if yes how?

要么

2- can i redirect to a specific method in the page to avoid calling the onload method every time? if yes how

要么

3- can i write any thing in the onload method that keep me calling the method only at the first time? if yes how

注意:我知道在Web應用程序中,每次頁面重新加載時都必須調用load函數,但是有什么解決方案我必須要解決這個問題嗎?

您可以通過重定向到刷新頁面

[urlOfCurrentPage] + "?redirected=true"

然后在onLoad方法中檢查URL中是否存在GET“重定向”參數,如果是,則跳過onload。

兩種選擇:

  1. 你可以使用cookies。 登錄時設置cookie並在加載期間檢查它。 然后在執行初始化后清除它,以便下次加載檢查將失敗。
  2. 您可以使用地址作為參數,例如?justLoggedIn ,或者#justLoggedIn之后的哈希值。 然后檢查並重定向到相同的url減去justLoggedIn部分。 #版本的優點是它實際上不會重新加載頁面,這與使用?時不同? 版。

暫無
暫無

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

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