Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    419
    Thanks
    18
    Thanked 2 Times in 2 Posts

    "listen" for specific button click - then redirect?

    This is a general question on if it's possible and how I'd go about it...

    I'm working on a site hosted through a blog-managing company. Sometimes their programming doesn't seem to let me do things that would normally be possible, so I have to find creative work-arounds.

    This time, It doesn't seem I can use javascript to change an href destination that is generated by their system. I want the user to go to a different page, when they click on that link.

    I can have a script find a specific href, but it can't change it for some reason. So I'm wondering if there's a way I can just have the script redirect the user if they click on that link? I know it seems like a long way round, but I don't see any other way to do this under the circumstances.

    Just in case it helps, here's what I thought would work, but didn't:


    Code:
    document.getElementById('elementName').href == 'http://www.newURL.com';

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,435
    Thanks
    85
    Thanked 4,912 Times in 4,873 Posts
    You said "button click" but then show the code for a link, not a button.

    A button wouldn't have an href property.

    Can you show the element you are actually trying to change??
    Be yourself. No one else is as qualified.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,608
    Thanks
    11
    Thanked 619 Times in 599 Posts
    take out one of your equal signs to actually change the href, you are comparing the href to a string url in your posted code...

    i don't know of any way they could be stopping you from changing it if you can reach it; there's no read-only on the dom. well, that's not 100% true, but it's close enough to true that i'm sure they aren't doing that on a public-facing site.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,435
    Thanks
    85
    Thanked 4,912 Times in 4,873 Posts
    LOL! So used to changing = to == that I didn't even notice that this one needs to be vice versa!
    Be yourself. No one else is as qualified.

  • #5
    Regular Coder
    Join Date
    Aug 2010
    Posts
    419
    Thanks
    18
    Thanked 2 Times in 2 Posts
    Oops! Didn't mean to really say button.

    I had tried with both == and just =. It didn't work. But I think it was another case me not fully paying attention. I think it's pulling the url a different way, via the ID (maybe from a stylesheet???). the code I'm trying to change is:

    <div class="rss-title"><a id="rss-title-11930659-1" href="" ></a></div>

    When I change the script to this, it seems to work:
    Code:
    document.getElementById('rss-title-11930659-1').href = 'http://www.site.com/newfolder/newpage.html';
    document.getElementById('rss-title-11930659-1').id = 'something_else';

    is there maybe a better way to do this?

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    29,435
    Thanks
    85
    Thanked 4,912 Times in 4,873 Posts
    Ahhh...that makes sense!

    See, the HREF is *BLANK*.

    SO that clearly means that SOME OTHER code is going in and filling in the HREF, later.

    And it apparently does it by referring to that ID.

    So by *changing* the ID, you are preventing the later code from changing the HREF, after your change.

    It's actually a pretty clever and sneaky way to do it.

    Only possible bad part: Maybe the other code is doing something important and will fail when it can't change the href. But if it seems to be working, be happy!
    Be yourself. No one else is as qualified.


  •  

    Posting Permissions

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