Solved

display history array in document

Posted on 1997-05-05
7
376 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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…

705 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

20 Experts available now in Live!

Get 1:1 Help Now