I need to know how to get the url of the referring page of my website. When a user clicks a link to a contact form on my website (from another page on my website) how can I get the url of that page? I have tried document.referrer but it only shows the domain name of my website, I need to see what page a visitor was viewing when they clicked on the link to the contact form. My site is static html, css and javascript.
Also tried setting a cookie, but it only shows the page where the contact form is actually located, for example: www.mysite.com/contact-us.html. What I need to know is what page the visitor was viewing when they clicked on the link that brought them to the form on the contact page.
My objective is to pass the url into a hidden form field, so when submitted, I can tell which page of my website the user was viewing when they clicked on the link to the contact form. Then, if they ask a question about a specific product, I will know which page they were on when they viewed the product. Note: I have 100 product pages that link to the contact form.
CodePudding user response:
If you have a master page used by all the product pages, you can save the current url as session in master page when the product page was loaded . Then you can retrieve the session url when contact page was loaded. This should able do the work.
CodePudding user response:
You can use the HttpRequest.UrlReferrer property.
Gets information about the URL of the client's previous request that linked to the current URL.
public partial class Contact : Page
{
protected void Page_Load(object sender, EventArgs e)
{
Uri urlReferrer = Request.UrlReferrer;
if (urlReferrer != null)
{
hiddenFieldUrlReferrer.Value = urlReferrer.ToString();
}
}
}