View Full Version : target url

09-25-2009, 01:20 AM
I'm new to Javascript and need some help. I have many pages with lots of links on them. I want to be able to change the destination url in Javascript after a link is clicked. Where is that information stored? The window.location object only stores information about the current window. Is there a property or method in the browser object that stores the target url? In other words, I have a link whose href is something like "www.somewhere.com". When I click that link, I want to trap it in onunload and add to it or change it as needed. How do I do that?

09-25-2009, 10:28 AM
Look, I'm not trying to bypass any kind of security or do something strange and funny to the browser or whatever. All I want to do is add to the querystring before it loads the target page. My pages allows users to select their own background image and I want to preserve that during the session and pass it to other pages. Doesn't anyone have any suggestions how I do that? I can't simply add it to each link's href since I don't know beforehand what image they will choose nor do I know which link they will click. I just thought the target url is kept somewhere and I can just add it to that (like www.somepage.com?bg_image). Please, any suggestions?

09-25-2009, 01:27 PM
I tried this and it worked. I just iterated through all the links on the page when a background image is selected and added ?imagename to the end of each href and that worked. When a page is loaded I retrieve it (with window.location.search.slice(1)||defaultimage) and then load the image in the background as normal. Thanks anyway...

09-26-2009, 02:22 AM
Javascript cannot do this sort of thing with any degree of reliability. However, on a session or day period basis, cookies may be employed to accomplish this sort of task for the vast majority of users. If the action (changing the link or links on the basis of a link having been clicked by a user) is mission critical though, a server side language (like PHP or asp) should be employed.

09-27-2009, 03:08 AM
I understand what you are saying, but I wanted to keep this on the client side and neither did I want to complicate things with cookies. If things get out of hand, which is an eventual possibility, I will indeed look into using php or some other server side solution. Thanks for the reply.