?
Solved

display history array in document

Posted on 1997-05-05
7
Medium Priority
?
400 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 5

Accepted Solution

by:
icd earned 50 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

800 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