display history array in document

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 ?



LVL 28
sybeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sybeAuthor Commented:
Edited text of question
0
jshamlinCommented:
"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
sybeAuthor Commented:
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

icdCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sybeAuthor Commented:
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
icdCommented:
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
grubanCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.