Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Urgent JS help needed



4:28 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

Here's a little background on what I'm trying to accomplish.

My main page (index.htm) has all of the navigation for the site.. pretty normal. Almost ALL of the links load external html files into a *dynamically* created layer (div) called "mainContent". I am also able to link to other files from within the 'mainContent" layer and they load into the same 'mainContent' layer within the index.htm file.

- I am NOT using an IFRAME anywhere (though I may have to to solve my problem)

This works perfectly, for the most part. Everything except a few pages that get loaded into new windows loads just fine into the 'mainContent' layer.

Here's the problem : The BACK button cannot be used with this method !

I need a way to make a 'back' button workable, even if its a back button that I create, long as it will take the user back in the history of external pages that have been loaded into the 'mainContent' layer.

It has been suggested to me that I could load the URL history into an array, and then access the 'history' in the array using a 'back' button. Well.. I've been slamming my head against that wall for 2-3 weeks and I just can't make it work :( My JS skills just aren't good enough to figure it out as soon as I need it.

Here is what was suggested:
var myHistory = []

function loadPage(url) {

function back() {

In this case, 'myLoadPanel' would be replaced with 'mainContent', the name of my main content layer.

I've tried and tried this, but I can't get it to work. Obviously I'm missing something/doing something wrong. Here is the script that is used for loading the external html files into the dynamic layer:

<a javascript:mainContent.setURL

1 - Is the definition attached here all that I need for the array to work ?
2 - Would I add the LoadPage function on the same line as the above link example ?
3- What scripting would I use for a 'back' button of my own making ???

I'm really, really stuck on this one, so if anyone can help me ASAP, I would greatly appreciate it. The site cannot go to QA for testing until this 'back button' problem is resolved.. and the site project is already 2 weeks behind (though not because of this) ! HELP!

If any more information is needed, I will gladly provide it either here or via email.. I'm getting to the point of desperation :(

Thanks in advance !


4:55 pm on Jul 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Switching to Iframes would solve MANY of your problems....

- the browser back button could be used.
- SEs could see the content of your 'sub' pages.

I'm sure you could get your solution to work but the above would be both easier and a better solution.


5:33 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

You're probably right, but I'm stuck now with a time constraint. How can I redesign a site with over 300 pages to now use IFRAMES ?? That is a huge thing to turn around and redo. I have thousands of links in all these pages, most of them are using the javascript I already have. I just don't have the time.

Besides, won't an invisible IFRAME with the same content as the layer just weigh down my pages ?? I don't need to make them slower, they need to be faster. I took this site from a 7-frame monster to NO frames. The Dynamic layers are VERY fast and I don't have to shift the content from an IFRAME to a div. The layers 'grow' lengthwise as needed and there are no hideous scrollbars like an IFRAME would need.

SE's ?? I'm not sure I know what you're referring to.. sorry. I have NO concern for any browser compatibility other than IE at this point either.

Thanks !


6:44 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

SE = Search Engine (as in: Google, Yahoo et al). Pretty important to make your pages SE-friendly. :)

The reason you can't load the History list into an array is because you're not allowed to for security reasons; you could use it to spy on people's surfing habits and the information you could gather would be worth a small fortune to spammers.

There is only one way of doing it:

1. Find a company that issues certificates, such as VeriSign.
2. Pay that company a substantial fee and fill out a lot of personal details on a long form.
3. Wait until your details have all been checked out. You may get a visit from a company rep.
4. Write your script. It must include the line netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead")
5. Digitally sign all the scripts on the page. This involves creating a .jar file for each.
6. Upload. If you discover an error in your script, you will need to go through the signing process every time you make an edit.
7. Hope all your visitors are using Netscape browsers.
8. Hope all your visitors will grant UniversalBrowserRead privilege.

That's kind of a tall order just to avoid breaking the Back button...


7:18 pm on Jul 29, 2002 (gmt 0)

10+ Year Member


First, this is an INTRANET_ONLY site, it will have NO exposure to search engines and the outside world.. their surfing habits to 'spy' on are of no consequence to me.... so, having said that..

why would I need to hope no one uses anything but Netscape ??? My target audience is IE only. I'm not using the Netscape Layer tag, I'm using DIV tags only.

As far as your 'one way' of doing it.. I beg to differ, as I've had input that says I CAN do it, and it does not entail a lot of complicated certificates, script-signing, or investigations.

Just for the edification of anyone who reads this, here is a bit of clarification on what I'm trying to do, and its NOT to circumvent browser security !:

"What you want to do... is something altogether different. You want to make your own little private history array, having nothing to do with the browser's history array. Yours only refers to URLs loaded into your own loadPanel. Those URLs are not recorded in the browsers history array."

loadPanel is an element of the DynAPI, a very slick API for DHTML, which is fairly advanced and can be found at SourceForge.net.

As if all these ads and other vehicles out there aren't tracking people's every move on the internet as it is, and they're NOT using signed scripts and certificates ! If I'm not mistaken, they're using sneaky little cookies.. which I personally keep a very tight lid on for my home pc.

Sorry that my dilemma is too radical a javascript/dhtml thing for this forum. Guess I won't get any help here !


8:39 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

Well, I certainly hope that your event trigger is not:

<a javascript:mainContent.setURL

Because that won't work at all. The event trigger needs to be set in the href attribute or the onclick attribute. But let's assume this is a typo.

1 - Is the definition attached here all that I need for the array to work ?

No, because your event trigger is wrong.

2 - Would I add the LoadPage function on the same line as the above link example?

If I am understanding the examples you have given here correctly (and not having looked at DynAPI in a long, long time), then your link would be something like:

<a href="javascript: loadPage('patient_check_in/sect_b_checking_in_patients.html');">This is a link</a>

3- What scripting would I use for a 'back' button of my own making?

Something like:

<a href="javascript: back();">Back</a>

and in the script element in the head:

function back() {

But, again, not remembering much of DynAPI, I'm not sure if this is the proper syntax. Try asking the DynAPI mailing list (if there is one).

Sorry that my dilemma is too radical a javascript/dhtml thing for this forum. Guess I won't get any help here !

Sorry we're all too dumb to help you. Thanks for your support! ;)


9:27 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

First.. I never said anyone here was too dumb to help. All I meant by that was that it seems no one here has used DynAPI or even looked at it to know what's possible. The guys who write that thing appear to be way ahead of the curve. That doesn't make anyone dumb, just uninformed ;) I didn't really appreciate the somewhat flagrant accusation that I'm trying to do something to get around browser security.

At least you seem to know of the existence of the DynAPI, and you're right, DynAPI 2 has changed significantly since Dan Steinman came out with the original. I found the original a few years ago and was able to successfully use parts of it. Version 2 is different and more complex. I HAVE asked for help on the list and they apparently don't like my 'newbie' questions. I have gotten ONE response with some helpful information in it. My point is that we ALL have to start somewhere in learning and using JS, I admit that I got in over my head before I should have. But, I have, and now I need to learn more fast to fix it.

Now, the example that I posted DOES work, it IS attached to the HREF tag (sorry, just noticed the 'href=' is missing in what I included) and it works VERY well for loading my external pages into my dynamic layer. You're right.. it was a typo.. or at a least a bad copy/paste.

The corrected link tag with script reads as follows:

<a href="javascript:mainContent.setURL('ar_follow_up/section_a_guidelines_for_making_corrections.html')"><img src="wrapper_images/lftmenu_ar_01.gif" border="0" name="armenu_01"></a>

Everything about this works perfectly, EXCEPT for not having a functioning 'Back'-type button. That is what I need to resolve, and only that.

All in all, even though part of my post <a href> tag was missing, you have helped to answer at least part of my questions. Since I AM attaching to the 'href', does that change your answers to my 1st two questions ?

Thank you :)


9:38 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

Why not just put 2 back buttons on each html page that gets called to this layer, one on top & one on the bottom.

<a href="#" onclick=javascript:history.back(-1)>BACK</a>

If it must be a button, then:

<input type=button value="BACK" onclick=javascript:history.back(-1)>

will give a standard OS button.


9:45 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

Hmmm... interesting thought.. I don't know if the javascript inside the layer will execute ...

The problem with the 'normal' History object is that the URL's for the pages being loaded into my dynamic layer are NOT added to the browser's history. Essentially the URL of the page never changes, you basically start with 'index.htm' and stay there. All the other pages, except for a few loaded into new windows, get called as an external html file and are loaded into the dynamic layer (mainContent) that is embedded in the index.htm page.

I hope that makes sense :)


9:49 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

If you are loading the data, then you ought to be able to store your own history, and implement a back link that way. Just push each url you load onto a stack. You might like to monitor the size of your stack and drop of more than a certain number of urls.


10:01 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

Thank you Olwen, that is *exactly* what I need to do :) My problem lies in my lack of experience and knowledge to accomplish what you have suggested :) I have been given code, as you've obviously read, but I'm having trouble making it work.

Thanks !


10:45 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

First.. I never said anyone here was too dumb to help.

Oh ... nevermind then.

Since I AM attaching to the 'href', does that change your answers to my 1st two questions

It depends. Again, I am operating a little in the dark here because I don't know how the DynAPI methods are constructed, but ... from what it looks like you have to be calling the loadPage function somewhere so that you can add the url to the myHistory array (I'm assuming here that that's what the push method does).

Looking at what you have posted here leads me to believe that you wouldn't be using the setURL method for these links like you are, but should instead be calling the loadPage function -- after all, what is the myLoadPanel.load(url) for? To me, it looks like the load method is what you use to load data into the div, so I would think you would have:

var myHistory = []

function loadPage(url) {
myHistory.push(url) // this should add the url to the myHistory array
mainContent.load(url) // this should change the url of the mainContent div

function back() {
mainContent.load(myHistory.pop()) // this should change the url of the mainContent div to the second-to-last url in the myHistory div

and you would call it like this:

<a href="loadPage('ar_follow_up/section_a_guidelines_for_making_corrections.html');"><img src="wrapper_images/lftmenu_ar_01.gif" border="0" name="armenu_01"></a>

Then you want the back button to look at the next-to-last url in the myHistory array (since the current page would be the last url). I guess that's what the pop method does. If so:

<a href="javascript: back();">Back</a>

should work.

I'd have to take a look at DynAPI to be sure though, and if you really are short of time you probably will want to harrass those unhelpful folks on the DynAPI mailing list... .


11:38 pm on Jul 29, 2002 (gmt 0)

10+ Year Member

Thank you, Moonbiter, your input does help my understanding of what I should be doing :)

I wasn't trying to insult anyone.. guess I'm too far into freak-out mode to get this working.. LOL...sorry.

I know you probably don't have time to dive into the DynAPI, but does this help you understand what I'm doing with it so far ? :

<script language="Javascript" src="src/dynapi.js"></script>
<script language="Javascript">
<script language="Javascript">
DynAPI.onLoad=function() {
mainContent = new LoadPanel("psmain.html");

mainContent.setSize(612,1200); // height will be overwritten by default

counter = 0;
var el = new EventListener();
el.onload = function(e) {
//status = 'got load event '+ counter++;

The API really is very cool, but the documentation for the current version leaves something to be desired. I've had one guy from the list send me something I think I can use to fix this, just have to plug it in and try it. Along with what you've told me, I just MIGHT beat this thing into submission.

Thanks !


6:41 am on Jul 30, 2002 (gmt 0)

10+ Year Member

Ah... creating your own special History list, that's fine. Sorry, I misunderstood.

While it is possible to write a script to keep track of individual visitors' progress through your site, and while it is vaguely possible (using really really sneaky stuff) to find out what they do when they leave, it's not easy. JavaScript is "hobbled", and it is simply not possible to read properties of documents that originate from a different domain. You can access properties of documents from other servers at the same domain (e.g. orders.mydomain.com and sales.mydomain.com) but that's it.

It doesn't change the fact that access to the browser's History list is severely restricted. It is; and that's all there is to it. You may think it futile, but complaining to me about it isn't going to achieve anything.


1:35 pm on Jul 30, 2002 (gmt 0)

10+ Year Member


I'm not complaining to you about anything ! You seem to miss my point.. my site is NOT on the internet, it is an INTRANET. It is NOT subject to any search engine, so I could care less about any SE 'compatibility'. I am NOT accessing ANYTHING outside of my own INTRANET server docs and I'm not tracking anything a user does except the pages loaded into my dynamic layer when they click links to files INSIDE my site. I don't care one little bit about 'tracking' anything else that's done or accessed in the browser, I don't care what they do when they leave the Intranet, and I'm not trying to be sneaky.

Perhaps my original request as to the 'browser's history' was inaccurate in relation to what I really need to do. You've read enough by now to know that I don't want to do anything with the actual BROWSER's history !


Featured Threads

Hot Threads This Week

Hot Threads This Month