473,698 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ma tch(/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 2030
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.ma tch(/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.javas cript 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.ma tch(/something/)) {
mylink.href="#" ;
mylink.onClick= "alert('clicked ');return false;";
}
}


You could try:

var mylink
for (var j = 0; j<document.link s.length; j++) {
mylink = document.links[j];
if (mylink.href.ma tch(/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(){aler t('clicked');re turn false;}

Mick

Oct 31 '05 #6

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

Similar topics

6
167424
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 I'm using on the parent page is ... <a href="#" onClick="popupcal()">choose date</a>
11
2016
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 new page with simply the value "" on it? I want the original page to remain unchanged.... thanks for the insight to a javascript n00bie... :) <a href="javascript:window.open('wireless.htm', 'pjtdetails', config='height=400, width=400, toolbar=no,...
14
2502
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. For example, here is the main page: <html> <head> <script type="text/javascript">
5
10881
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 works fine if I click to open in > the same window, but if I click the browser option to open in a > new window, the new window tries to open the href URL (the > onClick function does get executed, but seems to be ignored). > ...
4
6541
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 calendars.net/colchestercamra/#month, where I use JavaScript to set up the month. Could I use an 'onclick' to set up the properties of the <a> tag just before it jumps? I can't use window.location, as this currently remains static (using frames I'm afraid!).
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
26650
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, Jamie
4
16419
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 onClick event to call a script and pass the href URL and link text? That is; We'd like to put an identical piece of JS code into each
1
5530
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 would be great , if i know how to create the dynamic HREF links like it should be getting different document based on each userid. Here is my part of jsp code for your reference: <%@ page...
0
8678
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...
1
8899
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
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7737
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
6525
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
4371
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
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2333
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.