Results 1 to 5 of 5

Thread: target url

  1. #1
    Join Date
    Sep 2009
    Location
    inside a computer
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default target url

    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?

  2. #2
    Join Date
    Sep 2009
    Location
    inside a computer
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

  3. #3
    Join Date
    Sep 2009
    Location
    inside a computer
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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...

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Sep 2009
    Location
    inside a computer
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •