Solved

display history array in document

Posted on 1997-05-05
7
385 Views
Last Modified: 2011-09-20
What I want is to display the locations from the history array in a document.

According to Netscape's JavaScript Guide this line:

document.writeln("<B>history is</B> " + history)

would show the history of the browser.

It does not in Netscape (3.0, 3.01), and even gives an error in IE.

I can display history.length, that's all.

Any one an idea how to display the history array ?



0
Comment
Question by:sybe
7 Comments
 
LVL 28

Author Comment

by:sybe
ID: 1265398
Edited text of question
0
 
LVL 4

Expert Comment

by:jshamlin
ID: 1265399
"history" alone is the problem - you need to access the values stored in the history *array*, thus ...

var c = 0 ;
while (c != history.length + 1){
         document.write (history[c]);
       c++;
       }

This loops through each item in the history array and prints its value to screen - you can use other forms of loops if you prefer, or limit the max number of items to display.  You can also modify the document.write to add whatever ancillary text you desire.



0
 
LVL 28

Author Comment

by:sybe
ID: 1265400
This should work, but again, according to the Javascript guide, but it does not work in practice !
I have tried to display history[number] before, but nothing is displayed. Do you have an example that really works ??

So my question is not yet answered
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 5

Accepted Solution

by:
icd earned 25 total points
ID: 1265401
The script is correct but I understand that there was a change to browser software because it was felt that there was a security problem. The printing of the history was disabled although I think it is still possible to 'go' to a history entry.
0
 
LVL 28

Author Comment

by:sybe
ID: 1265403
Ok, I am satisfied with this answer. And I understand the "security" reason. In fact I wanted to use the history array to show visitors how not-anonymous surfing is. There is still lots of stuff to make surfers realize this though :)

It would have been nice if Netscape had informed the public about the change though. Well, maybe they have, and I just haven't seen it.


0
 
LVL 5

Expert Comment

by:icd
ID: 1265404
A few comments more.

The javascript given above by jshamlin assumes a MSIE browser where the array is counted [0],[1],[2],...etc. In Netscape however the history array is relative and is counted [0], [-1], etc.

You may be still be able to get the URL of the equivalent of history[-1] (Netscape) or history[1] (MSIE) by using:-

document.write(document.referrer);

I will be trying this tonight on my own web site.


0
 

Expert Comment

by:gruban
ID: 1265402
That answer could be explained better.

The window.history JavaScript object is considered a security risk - Netscape Co. doesn't want a script to automatically know what other pages a given user has visited. The script can freely use history.back(), history.forward(), and history.go(3) methods to send the user around, but it can't actually access the values of those URLs without asking for permission.

Here is how you ask the user for permission:
<SCRIPT>
netscape.security.PrivilegeManager.enablePrivilege(
      "UniversalBrowserRead");
document.writeln("<P>window.history: " + window.history);
</SCRIPT>
This will pop up a warning window - "This script is asking for a medium risk privilege". If the user agrees, the script will write out the history array, in table form. If the user does not agree, the script will write:[object History] for the whole object, or the empty string for each array element.
You only need to ask for permission once per script, not once per history access.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to hide the rows in Table when the value is empty ? 4 39
ASP.NET gridview select textbox on focus 2 33
Html5 Index on a table 7 25
simple javascript form validation 2 17
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

813 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

17 Experts available now in Live!

Get 1:1 Help Now