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
Solved

display history array in document

Posted on 1997-05-05
7
390 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Hide cell in a table 2 27
Html form and modal / img src -problem 3 29
Asp in script 6 37
How can I use an anonymous question as a Google Maps call-back function? 4 25
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

856 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