瀏覽器history操作實現一些功能

2022-03-10 06:10:57 字數 1548 閱讀 3553

功能:從廣告進入到落地頁後,給history增加乙個頁面,攔截返回動作

主要用到的是h5中的history物件,使用了pushstate,和replacestate來操作。

並且加入了一些條件判斷,包括 history.state, history.state.page,history.state.entered。

以上這些方法可以實現按需操作history物件。

但history操作後,按返回按鈕其實是只更新url位址,不重新整理頁面的,最終的重新整理頁面,是用 window.onpopstate 監聽,

在判斷條件符合後,手動去reload一次頁面。

以下就是實現該功能的**:

1/**

2* @note 從廣告渠道過來後,按返回按鈕時的攔截功能

3* @author kangxufeng

4* @create 17/08/08

5* @des 1.url中存在a_tuiaid時,啟用攔截功能

6* 2.插入state:的頁面

7* 3.當前頁面state:8*/

910;11 (function

() 22 } else

else

if (history.state && history.state.page == 'intercept') );

34 } else38}

39}40}

41}4243

})44

45function

initreturn() ,'',intercetpurl);

49 history.pushstate(,'',thislocation);50}

51 window.onpopstate = function

() ,'',intercetpurl);

57 updatetimes(function

() );60}

61}62}

63}6465

function

updatetimes(callback)

6869

function

istointercept() else76}

7778

function

getparams(name)

86 })(zepto);

返回上上個頁面

功能:首頁開啟商品詳情頁b,判斷售罄跳轉到售罄頁c,在c頁面點返回時略過b直接回到首頁。

關於瀏覽器的history

即history.replacestate 方法,這個方法接受三個引數,第乙個是狀態物件,第二個是頁面標題,第三個是頁面鏈結。具體 如下 if history.replacestate else history.replacestate 發放會替換當前頁面的瀏覽記錄,及頁面標題替換為 documen...

根據瀏覽器history模擬瀏覽器後退按鈕顯隱問題

措施 具體思路如下 1.開始開啟頁面時,瀏覽器的history.length為1,按鈕隱藏 2.當history.length 1時,點選按鈕執行 history.go 1 3.後退到歷史記錄棧中第一幀時,按鈕隱藏。出於瀏覽器安全性考慮,history中沒有給出屬性判斷其當前頁的位置,所以,在開始開...

讀取谷歌瀏覽器history 檔案

chrome上網記錄提取小試 history 知乎 zhihu.com chrome歷史記錄分析 巨獸 墨菲特 cnblogs.com 這個檔案是sqllite格式 python 讀取sqllite 1 coding utf8 23 4 author wang yanlong 5date 2017 ...