Overriding a href using onClick

V

VA

Firefox 1.0.7

If I launch Jesse Ruderman's Javascript shell

http://www.squarefree.com/2005/10/30/javascript-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
 
L

Lee

VA said:
Firefox 1.0.7

If I launch Jesse Ruderman's Javascript shell

http://www.squarefree.com/2005/10/30/javascript-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.
 
V

VA

Lee said:
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
 
R

Randy Webb

VA said the following on 10/30/2005 11:39 PM:
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
 
A

Andrew Poulos

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top