Musfiqur rahman
Musfiqur rahman

Reputation: 739

How to know the address of the webpage from which <a href="present page"> was clicked?

I have a login.asp page. Whenever the session expires, the user is given a link to the login page to log in. After logging in, users need to go back to the original page from which the link was clicked. How do I get the address of that webpage?

Upvotes: 2

Views: 68

Answers (3)

Mayank Kumar Chaudhari
Mayank Kumar Chaudhari

Reputation: 18538

There is a property of the document object called referrer

For example link to your website was clicked from http://example.com, you can use document.referrer to get http://example.com

Ref - https://www.w3schools.com/jsref/prop_doc_referrer.asp

Upvotes: 0

WhyNotHugo
WhyNotHugo

Reputation: 9916

You could redirect him to

/login.asp?next=url-of-where-the-user-tried-to-go

Once he logs in, redirect him to the parameter next. This is extremely common.

Upvotes: 1

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114367

You have to grab the referrer when the user is redirected to the login page. Store that and redirected the user back after the login process.

Upvotes: 2

Related Questions