473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Overriding a href using onClick

VA
Firefox 1.0.7

If I launch Jesse Ruderman's Javascript shell

http://www.squarefree.com/2005/10/30...ript-shell-14/

on any web page and type in the shell

var mylink
for (j=0;j<document.links.length;j++) {
mylink=document.links[j];
if (mylink.href.match(/something/)) {
mylink.href="#";
mylink.onClick="alert('clicked');return false;";
}
}

I expected all my links having "something" in them to now popup my
alert box.

But nothing happened, no errors in the Javascript console, nothing
happens when I click on those links.

What gives?

Thanks

Oct 31 '05 #1
5 2002
Lee
VA said:

Firefox 1.0.7

If I launch Jesse Ruderman's Javascript shell

http://www.squarefree.com/2005/10/30...ript-shell-14/

on any web page and type in the shell

var mylink
for (j=0;j<document.links.length;j++) {
mylink=document.links[j];
if (mylink.href.match(/something/)) {
mylink.href="#";
mylink.onClick="alert('clicked');return false;";
}
}

I expected all my links having "something" in them to now popup my
alert box.

But nothing happened, no errors in the Javascript console, nothing
happens when I click on those links.


Links don't have an onClick attribute.
They do have an onclick attribute, but it should be assigned a
reference to a function, not a string value.

Oct 31 '05 #2
VA
Lee wrote:
Links don't have an onClick attribute.
They do have an onclick attribute, but it should be assigned a
reference to a function, not a string value.


So how would I modify my snippet above to do what I want it to do?

Thanks

Oct 31 '05 #3
VA said the following on 10/30/2005 11:39 PM:
Lee wrote:
Links don't have an onClick attribute.
They do have an onclick attribute, but it should be assigned a
reference to a function, not a string value.

So how would I modify my snippet above to do what I want it to do?


You change onClick in your code to onclick

CaSe MaTtErS

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 31 '05 #4
> var mylink
for (j=0;j<document.links.length;j++) {
mylink=document.links[j];
if (mylink.href.match(/something/)) {
mylink.href="#";
mylink.onClick="alert('clicked');return false;";
}
}


You could try:

var mylink
for (var j = 0; j<document.links.length; j++) {
mylink = document.links[j];
if (mylink.href.match(/something/)) {
mylink.href = "#";
mylink.onclick = function() {
alert("clicked");
return false;
}
}
}
Andrew Poulos
Oct 31 '05 #5
VA wrote:
Lee wrote:
Links don't have an onClick attribute.
They do have an onclick attribute, but it should be assigned a
reference to a function, not a string value.

So how would I modify my snippet above to do what I want it to do?


mylink.onclick=function(){alert('clicked');return false;}

Mick

Oct 31 '05 #6

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

Similar topics

6
by: Jez | last post by:
Hi, I've created a function which opens a popup window containing a calendar. When a day is clicked, the date is entered into a text box on the parent page and the popup is closed. The link...
11
by: Dana Smith | last post by:
Can anybody explain why when I have a hyperlink on a page with the code similar to below, after the user clicks on the link, the desired window opens but the page with the hyperlink changes to a...
14
by: Brandon Hoppe | last post by:
I'm trying to change the src of an ilayer in the parent document from a link inside the ilayer. I'm not able to get it to work. All that happens is Netscape 4 crashes. This is for Netscape 4 only....
5
by: Mike | last post by:
In my previous post, I wrote: > ... > GOAL: (very simple) Provide a hyperlink which, when clicked, > calls a javascript function which opens a new URL. > ... > PROBLEM: The following code...
4
by: Robert Atkinson | last post by:
I have hyperlink, <a class='navbar' href="http://my.calendars.net/colchestercamra/">Diary</a>, that points to a calendar. What I want to be able to do is jump to...
2
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...
4
by: Jamie Jackson | last post by:
I know that it's possible to return false in an onClick to disable a link. Is there a way to do this within the HREF attribute? Something like: <a href="javascript: return false;"> ? Thanks,...
4
by: Jerry Sievers | last post by:
JS Programmers, "I'm a server-side coder PHP, Postgres etc... My question; Given the following anchor <a href="http://www.somesite.com/somefile.html">link text</a> Is there a way to code an...
1
by: nsvmani | last post by:
Hi, i am trying to get the FileOpen dialogue window as soon as clicked href link I am using IE6 with ActiveX enabled. Just need to get the File Open dialogue window when i click on the HREF links.It...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.