473,695 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onClick method question (this.href and document.locati on.href)

Hello all

I am trying to modify the link URL when a user clicks on the link.
Following is the code:

<a onClick="docume nt.location.hre f=modifyURL(thi s.href);"
href="SOME_DYNA MIC_URL" %>Link</a>

The javascript function, modifyURL(href) , works fine and returns the
desired URL, but for some reason, the value of 'href' is not getting
overwritten with the value returned from the js function. It works fine
if I use the following code:

<a onClick="this.h ref=modifyURL(t his.href);" href="SOME_DYNA MIC_URL"
%>Link</a>

But the reason I'm trying to use document.locati on instead is because
of an IE bug. The string 'Link' actually contains the character '@', if
I use this.href, the URL will be formed perfectly, but right before the
page redirects to the new location, the whole URL will be printed on
the page (replacing the string 'Link'). This "bug" is overcome by using
document.locati on, but then the URL is not getting updated. Any ideas?
Thanks a lot
-Yogesh

Jul 23 '05 #1
2 41496
Lee
yo************* @gmail.com said:

Hello all

I am trying to modify the link URL when a user clicks on the link.
Following is the code:

<a onClick="docume nt.location.hre f=modifyURL(thi s.href);"
href="SOME_DYN AMIC_URL" %>Link</a>


You're telling the browser to do two things that conflict.
1) set document.locati on.href to some URL
2) follow the link to "SOME_DYNAMIC_U RL"

You can cancel action #2 by having the onClick handler return false.

onclick="docume nt.location.hre f=modifyURL(thi s.href);return false"

Jul 23 '05 #2
Great! that works. Thanks Lee.

-Yogesh

Lee wrote:
yo************* @gmail.com said:

Hello all

I am trying to modify the link URL when a user clicks on the link.
Following is the code:

<a onClick="docume nt.location.hre f=modifyURL(thi s.href);"
href="SOME_DYN AMIC_URL" %>Link</a>


You're telling the browser to do two things that conflict.
1) set document.locati on.href to some URL
2) follow the link to "SOME_DYNAMIC_U RL"

You can cancel action #2 by having the onClick handler return false.

onclick="docume nt.location.hre f=modifyURL(thi s.href);return false"


Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5737
by: Draken | last post by:
I have a function in the head section of a html and call it from a radio button with onClick="menu();" but IE tells me that the object doesnt support this method or property. What is the problem with that? I have tried numerous ways around it but to no avail. <head> function menu() { for (i=0;i<=2;i++) { if (document.menuform.menu.checked=="1") { parent.main.location.href="document.menuform.menu.value + '.html'" }
17
61433
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to programmatically issue a JavaScript statement which causes the browser to act just like the user clicked on a link in my page. And if that link has an onClick JS event defined, I'd want that onClick event to execute too, exactly the same as if the user...
2
9163
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display in the status bar 'Symantec Corporation' whenever anyone mouses over (onMouseOver) my image or link OR when one clicks while holding the left mouse down (onClick) on the same image or link. Upon releasing the mouse (onMouseOut), the
4
2804
by: chris | last post by:
if i eun this page in IE or netscape it works fine, <select name="select" onChange="javascript:location.href = this.options.value;"> <option value="" >this page </option> <option value="" >another page</option> </select> but i would rather have a button for the user to click rather than an onchange
3
3263
by: Jamie Jackson | last post by:
I'm rewriting all links' onclick events, but I'm having a problem. The onclick event that I'm inserting works correctly in Opera, but not in FF or IE. I'm retroactively adding the statement "return promptBeforeOpening();" FF and IE rewrite it as I would expect them to, but it turns out that that doesn't work (no disclaimer pops up, and the link is not disabled):
53
81720
by: usenet | last post by:
See <ul> <li><a name="link1" onClick="alert(this.name);return false;" href="#">Link1</a></li> <li><a name="link2" href="javascript:alert(this);">Link2</a></li> <li>Item 3</li> </ul> Clicking on the first list item gives me "link1" because "this" refers
1
4672
by: Regena | last post by:
hi, I have an image and when a "href" associated with it. on href it should go to "link1" for example and onClick I have to call a javascript function. the way I do is: <a href = "link1" ><img src="something" name="something" onClick="javascript function();"></a> the way its working is onClick its performing the javascript function
5
2113
by: Fred.Grieco | last post by:
Hi every body, I have a little pb and I'm turning around : function MyFCTN(var1,var2) { var mytable = document.getElementById("myTBL"); for (var i=myTBL.childNodes.length-1; i>0; i--){ myTBL.removeChild(myTBL.childNodes); } for(var i=0; i<var1.length; i++){
9
8554
by: whitgurley | last post by:
I've searched the web as well as I can for a solution to this problem but have found nothing and just don't know enough about JavaScript to figure out what's going. What I'm trying to do is convert this script: <a href="#" onclick="MM_goToURL('parent.frames','color2.html');return document.MM_returnValue">TEST</a> ....to something that I can use within a Flash movie, which as far as I can tell means that it needs to reside in the...
0
9132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8864
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3024
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2288
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.