I’ve put an alert into the onUnload event and I want to to display the url of the page that is about to be loaded.
I can’t think of the Javascript for it. Location.href gives the current url and window.history only gives previous urls visited. The link has been clicked at this stage so the browser must know the destination url, but where do I find it.
The idea is that when a user leaves a document that’s in edit mode, prompt comes up asking them if they want to save their changes. If they click Ok, then I want to put the url that they were going to into the $$Return and submit the document.
I’m not aware of any JS event which conforms to what you’re trying to do, but have an idea. Why not trap for this in the onclick event of whatever code is generating the link? That could then be fed into a temporary field to be used to set $$Return. Or, you could in the onClick event of your link actually put in the confirm method and handle it that way.
Subject: RE: Getting Destination URL using Javascript
Thanks for the reply.
It’s a shame there is no way to grab this information, reletivly simple I would have thought.
I can’t really put the code into each link as that will leave too many holes and make it inconsistent. Users wouldn’t be prompted if they typed in a new URL manually or clicked a favorite etc.
I think I might just submit the document and make them click the intended link a second time.
Subject: RE: Getting Destination URL using Javascript
I think I can’t have explained it properly. I’m trying to create an effect like most applications. E.g. you close word and it asks you if you want to save your changes or lose them.But as well as losing your changes by closing the browser, you can lose your changes by navigating to any other page. So I want to prompt the user when ever the page is Unloaded in any way, not only when they click a link that I generated.
Subject: RE: Getting Destination URL using Javascript
Thanks for the clarification, Ross. Now I understand your predicament better. Have you tried putting a confirm statement in and then setting continue to false if the user doesn’t select OK? Would that work in the scenario in which you’re planning to use it?
Subject: RE: Getting Destination URL using Javascript
That’s basically what I’ve done.
I’ve put an onChange event on every field that can be edited, saying put a value into the ConfirmSave field if this field is changed.
Then onUnload if this ConfirmSave Field has a value in it, I know there have been changes so I give them a confirm pop up, “Do you want to save your changes?”, if they click okay, it just submits the document rather than taking them to the URL they were trying to get to, meaning that after the save they have to click that link or enter that URL again. And if they click cancel, they continue without saving.
Then I’ve had to had a few bits in to stop the prompt if a saving type action is called, or they will click save and then be asked if they want to save there changes which wouldn’t be good.