Reputation: 3049
Is there a way to detect the previous URL that user visited before arrive on my website using javascript or jQuery?
I hope it can be possible avoid using PHP
Upvotes: 0
Views: 923
Reputation: 12017
You seem to want to get the previous URL when the user directly enters the new URL in the browser without clicking a link. This is not possible in PHP or JavaScript. It would be a significant and quite unnecessary security risk, so browsers will refuse to send it. You can only get it through the referrer if the user clicked a link on the previous website that redirected them to yours.
Frankly, there should be no reason for the new website to know about the previous one unless the user was referred from the previous URL by clicking a link.
Upvotes: 1
Reputation: 2244
document.referrer
I think is the most common one. There is also the history api
Upvotes: 1