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 10-19-2010, 04:51 PM   PM User | #1
skanandron
New to the CF scene

 
Join Date: Oct 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
skanandron is an unknown quantity at this point
adding javascript to a link

I have a simple problem. I want to add the current page's url to a link, like this:
<code>
<a href="http://www.somesite.com/somepage.aspx?a=">
</code>
After the 'a=' I need to add javascript that will return the current url. It can be the full url (example: http://www.codingforums.com/newthrea...=newthread&f=2) or a partial one (example: /newthread.php?do=newthread&f=2).

Can someone help me with an example?
skanandron is offline   Reply With Quote
Old 10-19-2010, 05:33 PM   PM User | #2
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 976
Thanks: 0
Thanked 203 Times in 198 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Try: <a href="http://www.somesite.com/somepage.aspx?a=" onclick='location.href=this.href+window.location.href;return false;'>

Last edited by Logic Ali; 10-19-2010 at 08:33 PM..
Logic Ali is offline   Reply With Quote
Old 10-19-2010, 06:05 PM   PM User | #3
skanandron
New to the CF scene

 
Join Date: Oct 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
skanandron is an unknown quantity at this point
Thank you. This isn't sending the querystring though.

<a href="http://www.somesite.com/somepage.aspx?a=" onclick='location.href=this.href+window.location.href'>

goes to

www.somesite.com/somepage.aspx?a=
skanandron is offline   Reply With Quote
Old 10-19-2010, 06:31 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Try this:-


Code:
<a href="#" onclick="goURL()" return false;>Click here</a>

<script type = "text/javascript">
function goURL() {
var x = window.location.href;
var url = "http://www.somesite.com/somepage.aspx?a=" + x
window.location = url;
}
</script>
Philip M is offline   Reply With Quote
Old 10-19-2010, 07:14 PM   PM User | #5
skanandron
New to the CF scene

 
Join Date: Oct 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
skanandron is an unknown quantity at this point
Thank you Philip! That did it!
skanandron 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 05:33 AM.


Advertisement
Log in to turn off these ads.