Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
Get previous URL with javascript

I am looking for a solution with javascript to check if the previous page is not extranal.

With this check I want return true or false so I can use this for another function.

What I have tried is to get the previous URL with history.go(-1)but this is undefined.

I am happy if I can get the previous URL so far.

Hope somebody can help me out with this.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use document.referrer to get the URL of the previous page.

To check whether it is external or not, you can parse it with the URL constructor and compare its origin.

const previousURL = document.referrer;

const isPreviousURLExternal = new URL(previousURL).origin == new URL(location).origin;
console.log(isPreviousURLExternal)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!