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
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 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??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,401
    Thanks
    11
    Thanked 595 Times in 575 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.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    LOL! So used to changing = to == that I didn't even notice that this one needs to be vice versa!
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #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
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 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!
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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