473,769 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using <a href="a(this")>

can someone please tell me why everytime i try and pass this to a js
function i can't seem to use it for anything:

<html>
<head>
<script language="javas cript">
function a(fromlink) {
alert(fromlink. nodeName); // outputs undefined
alert(fromlink. nodeType); // outputs undefined
alert(fromlink. parentNode); // outputs undefined

// i might as well be writing:
alert(fromlink. blahblah_not_a_ member);
}
</script>
</head>
<body>
Some body text<br />
<a href="javascrip t:a(this)">This is a link</a>
</body>
</html>

what am i doing wrong? this is driving me mad
Oct 7 '05 #1
3 1752


Oliver Saunders wrote:

<a href="javascrip t:a(this)">This is a link</a>


You want
<a href="#"
onclick="a(this ); return false;">
Inside of an event handler the this object is the element the event
handler is attached to.
A javascript: URL in a href attribute is not an event handler.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 7 '05 #2
Lee
Oliver Saunders said:

can someone please tell me why everytime i try and pass this to a js
function i can't seem to use it for anything:

<html>
<head>
<script language="javas cript">
function a(fromlink) {
alert(fromlink. nodeName); // outputs undefined
alert(fromlink. nodeType); // outputs undefined
alert(fromlink. parentNode); // outputs undefined

// i might as well be writing:
alert(fromlink. blahblah_not_a_ member);
}
</script>
</head>
<body>
Some body text<br />
<a href="javascrip t:a(this)">This is a link</a>
</body>
</html>

what am i doing wrong? this is driving me mad


The "javascript :" pseudo-protocol functions similarly to the "http:"
protocol, except that the new contents for the current window come
from the output of your a() function, instead of from a web server.
If the output happens to be void, then the contents are unchanged.
You're abusing this mechanism for the side-effect of executing the
function.

Your a() function executes in the context of the window whose content
it is replacing, so "this" is a reference to the window, not to the
link. You can see that if you add the line:

alert(fromlink) ;

Oct 7 '05 #3
> You want
<a href="#"
onclick="a(this ); return false;">
Inside of an event handler the this object is the element the event handler is attached to.
A javascript: URL in a href attribute is not an event handler.
ah huh thank you.
Your a() function executes in the context of the window whose content
it is replacing, so "this" is a reference to the window, not to the
link. You can see that if you add the line:

alert(fromlink) ;

yes actually I did notice that. thanks for clearing that up.
Oct 7 '05 #4

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

Similar topics

6
2590
by: lecichy | last post by:
Hello. Well, I found this piece of code on php.net. Thats fine but where can i find explanation for all these ("|\')?(*)("|\')?.*>(*)' syntax so that I can construct my own rules for all kind of eregi preg and oter match functions ?
14
13086
by: Gregory | last post by:
Hello, I'm trying to do the above in order to process an image and return the result to an html image control. It fails and my key suspects are either the variable that I'm passing in - ImageName - for processing, or the return data which is done (or not as the case may be) by imagejpeg($img) in the script, after header("Content-type: image/jpeg"). Any insights would be most welcome, especially debugging techniques and a pointer to...
1
27907
by: Jesper Hermansen | last post by:
Hi! I'm making a system that will generate Winamp-playlists. To make it easy for the user to add a file to the list, I'm using <input type="file">. The problem with this is that I only get the filename, not the path, which is necessary in my situation. I cracked the problem in Firefox:
10
60720
by: Dieter Salath? | last post by:
Hi, in our webpage, a user could open a windows explorer to his temp directory with a simple link and usage of the file protocol: <a href="file://C:\temp" target="_blank">C:\temp</a> This worked very well a long time, but now it does not work anymore. We use IE6 and Microsoft Windows XP Professional 2002 SP2. I guess it has something to do with new IE security features. Does
10
3757
by: Gernot Frisch | last post by:
Hi, I'm currently writing: <span onclick="window.open(...);">Klick Here</span> but I want to use the <a href> for this, since it is defined in the css script the way I want my link to open. Now, if I use a href, the href will be executed as well. What can I du in order to make the href not execute if javascript is enabled?
7
2775
by: Jim in Arizona | last post by:
Using this: <asp:ListItem Value="0"</asp:ListItem> as long as I have a value listed and leave the area between the tags blank, when viewed the DropDownList will show a 0 as a choice. I want it to be blank. I've tried doing this: <asp:ListItem Value="0">&nbsp;</asp:ListItem>
1
2439
by: mark4asp | last post by:
<form runat="server"automatically adds <divtag to code contained within. Is there a way to stop that? Mixing block-level elements with inline-level elements messes up the HTML becasuse that is invalid for a strict implementation. <spanis in-line-level and <divis block-level. I don't want to mix up <span> and <div> I'm using an <asp:Buttonhere because when it switches to the URL I need to check that the user is in the correct role -...
10
25424
by: vunet.us | last post by:
What is the workaround of passign a parameter to any included asp file: <!-- #Include File="file.asp" --> This obviously does not work: <!-- #Include File="file.asp?id=123" --> Thank you
36
5115
by: Roedy Green | last post by:
The only browser I have encountered that supports <colgroup><col class="behold"></colgroup> to apply a CSS style to a whole column, is Microsoft Internet Explorer. I have been told it SHOULD NOT do so, since this is not part of the specification. How then to you apply styles to entire columns? Surely you don't have to write <td class="behold"on every row item.
0
9424
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
10051
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
10000
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
8879
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
7413
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
5310
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
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
2815
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.