473,795 Members | 2,999 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 41508
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
5739
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
61445
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
9183
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
3271
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
81746
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
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10448
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...
0
10217
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
10167
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
9046
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
7544
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
6784
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
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.