Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-12-2011, 05:47 PM   PM User | #1
turpentyne
Regular Coder

 
Join Date: Aug 2010
Posts: 312
Thanks: 10
Thanked 1 Time in 1 Post
turpentyne is an unknown quantity at this point
"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';
turpentyne is offline   Reply With Quote
Old 09-12-2011, 07:44 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-12-2011, 08:50 PM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 09-12-2011, 08:52 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-12-2011, 09:24 PM   PM User | #5
turpentyne
Regular Coder

 
Join Date: Aug 2010
Posts: 312
Thanks: 10
Thanked 1 Time in 1 Post
turpentyne is an unknown quantity at this point
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?
turpentyne is offline   Reply With Quote
Old 09-12-2011, 09:58 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:04 AM.


Advertisement
Log in to turn off these ads.