mike55 Posted November 24, 2006 Posted November 24, 2006 Hi all I am using the following code to get the name of the previous page that the user visited: Private Function GetPreviousURL() As String Dim script As String = Nothing script &= "<script language=JavaScript id='previous'>" & vbCrLf script &= "document.referrer;" & vbCrLf script &= "</script>" & vbCrLf 'Verify script has not already been registered. If Not ClientScript.IsStartupScriptRegistered("previous") Then 'Register the script. ClientScript.RegisterStartupScript(Page.GetType, "previous", script) End If End Function [code] My only problem is that I am unsure as to how to get the value generated by document.referrer back to a vb.net variable. Any suggestions? Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
MrPaul Posted November 24, 2006 Posted November 24, 2006 Request.UrlReferrer There is no need to use client-side scripts for this. You can use just: Private Function GetPreviousURL() As String Return Request.UrlReferrer End Function Good luck :cool: Quote Never trouble another for what you can do for yourself.
mike55 Posted November 25, 2006 Author Posted November 25, 2006 There is no need to use client-side scripts for this. You can use just: Private Function GetPreviousURL() As String Return Request.UrlReferrer End Function Good luck :cool: Thanks for the reply MrPaul. Would love to be able to use that simple command, however, it appears not to work on all occasions. When I call it, it throws an exception, and all hell breaks loose. Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted November 25, 2006 Administrators Posted November 25, 2006 On what occasions doesn't it work? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
mike55 Posted November 28, 2006 Author Posted November 28, 2006 Ok, the code: Request.UrlReferrer.AbsoluteUri works correctly, if I am moving from page A to B. The problem arises when I use the browser back button to go from page B back to A, or a button that I have added to the page that redirects the user back to page A. I have had a number of problems with the above command in that it does not always have a value, thus causing me problems. Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Administrators PlausiblyDamp Posted November 28, 2006 Administrators Posted November 28, 2006 You are probably going to encounter the same problems via Javascript that you are encountering from .Net - the Referer will only contain a valid value when you have been referred to the current page (i.e. following a link or submitting a page). Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.