0

Page A contains a DetailsList, which has links to different pages. Page B contains a file viewer web part.

Clicking on any of the links on "Page A" DetailsList row items, directs the user to "Page B".

I am trying to fetch the Page A url using document.referrer but it returns a blank value. Rarely it gives the correct url.

Is there any way to ensure the document.referrer returns the correct url?

1 Answer 1

0
  • Since version 85 of Chrome, the default referrer policy has changed from no-referrer-when-downgrade to strict-origin-when-cross-origin.

  • document.referrer will only work if the person got to the current page through a link, or clicking something.... not if they were redirected through other means.

  • If you rely on the referrer header for your API, best is to specify the referrerPolicy for these calls as follows:

await ctx.httpClient.post(creatorUrl, HttpClient.configurations.v1, {
  headers: {
    "Authorization": `Bearer ${token}`,
    "content-type": "application/json",
  },
  referrerPolicy: 'no-referrer-when-downgrade', // Provide `referrerPolicy` option for falling back to the previous default
  body: JSON.stringify(msg)
});

Refer the below article for more details.

1
  • I understand that clicking a link is required. In my case too I click on a link to navigate to a different page. I'll try specifying the referrerPolicy. Mar 9, 2022 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.