Solved

How to get previous URL in IE?

Posted on 2001-07-01
23
15,316 Views
Last Modified: 2012-06-22
Dear All,

Does anybody know how to obtain the URL of the previous page visited under IE?
I find that many window.history properties as below only support Netscape.

window.history.current
window.history.previous
window.history.next

So how?  It should be simple!  But cannot find solution in my 2-inch-thick Javascript reference.  Please help.



0
Comment
Question by:kennon2000
  • 10
  • 5
  • 3
  • +4
23 Comments
 
LVL 1

Expert Comment

by:jmulder
Comment Utility
window.history.current
window.history.previous
window.history.next

Are all suported from NS3 and IE4 onwards.

You can use...

prevURL = window.history.previous;

document.write( "The previous history string is: " + prevURL);
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Huh - jmulder, how do you get that info???

Only NETSCAPE and ONLY with a signed script using UniversalBrowserRead access may look at the history.

You can look at document.referrer if is is set, but that is only the case if the previous page was a web page too - so not bookmarks or url typed in or dropped

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
document.write(history.toString())
netscape.security.PrivilegeManager.disablePrivilege("UniversalBrowserRead");


Michel
0
 
LVL 12

Expert Comment

by:ahosang
Comment Utility
These are not supported in IE, and even in Netscape need signed scripts.
0
 
LVL 12

Expert Comment

by:ahosang
Comment Utility
Sorry to repeat what you said Michel, your comment was not there when I posted :-)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
LOL

Michel
0
 
LVL 1

Expert Comment

by:jmulder
Comment Utility
Oops!

I forgot to add the line:

netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");

at the top of the example.

I got it from my Sams manual: Pure JavaScript by Wyke, Gilliam and Ting. pg 748.

Funny...this book is usually quite accurate :(

Didn't mean to cause an avalanche of disgust.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
LOL - does it say it is supported by IE4 - and then has
netscape.security.PrivilegeManager ???
Hmmm

Michel
0
 
LVL 1

Expert Comment

by:jmulder
Comment Utility
>> does it say it is supported by IE4

Yep. JavaScript1.1+, ECMASCript1.0+, JScript3.0+, Nav3+, IE4+

And in the appendix in the list for IE-supported syntax is: history.next, history.previous, history.current

The example given has a note which reads:
"In Navigator 4 and later, getting the next value requires the UniversalBrowserRead privilege."
0
 
LVL 2

Expert Comment

by:serg111
Comment Utility
Actually you can get previous page under document.referrer
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
As I already said:
"You can look at document.referrer if is is set, but that is only the case if the previous page was a web page too - so not bookmarks or url typed in or dropped"

Michel
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Expert Comment

by:rxolotl
Comment Utility
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Huh?

Michel
0
 

Author Comment

by:kennon2000
Comment Utility
imulder, I am the one who ask this question.  I actually use exactly the same reference book to you.  But when u used these properties become "undefined" in IE.  Then I found in a web stating that those properties work only in Netscape.
Now the question become: if I use document.referrer, I still cannot get the previous URL, what should I do?

Can I do it by VBScript or JScript instead?  I accept these two languages even though they may not work in Netscape.

0
 
LVL 1

Expert Comment

by:jmulder
Comment Utility
>> You can check this link
>> http://www.webreference.com/dhtml/column34/4.html

A very interesting article about "Speeding Up Frame Rates For DHTML Animation in Win98" :-?

kennon2000
As you can see from my posts...I have no experiance using this call...I just looked it up for you...the others seem to have more info.

>> I actually use exactly the same reference book to you.

It's usually a very good book.
0
 
LVL 7

Expert Comment

by:cstsang
Comment Utility
Try this one!
<script language=javascript>
   alert("The previous page URL is "+document.referrer);
</script>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Come on  cstsang  - you have been a member long enough not to answer a question that has many comments - TWO of which are using what you suggest!!!

Kennon: Please reject cstsang's answer

Thanks

Michel
0
 
LVL 1

Expert Comment

by:jmulder
Comment Utility
I only ever post comments since I believe there is always the possibility (and sometimes probability) that someone can give a better solution.

So, is it possible to remove an answer (or change it to a comment) if it where accidently posted as such?
0
 

Author Comment

by:kennon2000
Comment Utility
Of course I will reject cstsang's answer as it is actually not proposed by him.
But...could anyone can give me any possible suggestion to solve this problem? It is very different between getting a previous document and getting the previous URL.

Kennon2000
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
If the document.referrer works for you, that is the one to use.

Michel
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 80 total points
Comment Utility
Otherwise you are out of luck unless the page you visited is on your site and you can set a cookie

Michel
0
 

Author Comment

by:kennon2000
Comment Utility
Although it is not exactly what I want, Michel gave me a possible approval.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Sorry I could not be of more service...

If you are desparate and the user allows you, you might use wsh to read the MRU list (most recently used) off the registry, but I guess you are not THAT desparate ;-)

Michel
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now