473,804 Members | 3,903 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 41509
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
5740
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
61449
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
9185
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
2808
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
3272
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
81751
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
4676
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
2133
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
8560
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
9710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
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,...
1
7626
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
6858
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
5527
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...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4304
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
3
3000
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.