...

View Full Version : "listen" for specific button click - then redirect?



turpentyne
09-12-2011, 05:47 PM
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:





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

Old Pedant
09-12-2011, 07:44 PM
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??

rnd me
09-12-2011, 08:50 PM
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.

Old Pedant
09-12-2011, 08:52 PM
LOL! So used to changing = to == that I didn't even notice that this one needs to be vice versa!

turpentyne
09-12-2011, 09:24 PM
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:

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?

Old Pedant
09-12-2011, 09:58 PM
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum