[筆記] JavaScript: document.referrer

YY
Jan 22, 2021

--

Photo by Bec Brown on Unsplash

純記錄

document.referrer

在 client side 可透過 document.referrer 拿到 referrer 亦即 request header 中的 referer

Note 1

按下瀏覽器重整按鈕,document.referrer 維持原樣

呼叫 location.reload()document.referrer 會變當前 URL

(Chrome)

Note 2

發現 referrer 不如預期可能跟自行處理 history state 有關

例如 link click handler 先 pushState 到新的 URL 再 navigate,則 referrer 會拿到 pushState 的 URL

Note 3

referer is actually a misspelling of the word “referrer”

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

YY
YY

Written by YY

為五斗米折腰的前端打雜仔

No responses yet

Write a response