473,473 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

BASE HREF and A HREF="#" onclick="..."

Hey everyone,

I've looked for this and I wouldn't know what the best practice would be
for solving the following problem.

We use a BASE tag in our HTML pages. Now we have some links that use the
<A HREF="#" onclick="...">Hello</Amethod to invoke a JavaScript.
However, because of the BASE tag, when clicking a link containing only a
# as 'href' it will load the root index.html file. What I want is it to
do nothing and execute the onclick handler.

Now I have two possible solutions:

- Replace the # with javascript:... and remove the onclick handler.
- Replace the A HREF by a SPAN having the same style as a link.

Both however, I've learn it isn't good practice to use javascript: in a
link. The SPAN as link would be a sort of Sim-HREF, which will probably
end up being trouble (span:hover anyone?). Anyone has a viable solution,
cause I must be missing something.

Thanks in advance,
Vincent
Jul 6 '06 #1
2 5134
Vincent van Beveren wrote:
Hey everyone,

I've looked for this and I wouldn't know what the best practice would be
for solving the following problem.

We use a BASE tag in our HTML pages. Now we have some links that use the
<A HREF="#" onclick="...">Hello</Amethod to invoke a JavaScript.
However, because of the BASE tag, when clicking a link containing only a
# as 'href' it will load the root index.html file. What I want is it to
do nothing and execute the onclick handler.

Now I have two possible solutions:

- Replace the # with javascript:... and remove the onclick handler.
- Replace the A HREF by a SPAN having the same style as a link.
Return false in the onclick handler.
Jul 6 '06 #2
Why did I not think of that...

Thanks Robert!
Vincent

Robert wrote:
Vincent van Beveren wrote:
>Hey everyone,

I've looked for this and I wouldn't know what the best practice would
be for solving the following problem.

We use a BASE tag in our HTML pages. Now we have some links that use
the <A HREF="#" onclick="...">Hello</Amethod to invoke a
JavaScript. However, because of the BASE tag, when clicking a link
containing only a # as 'href' it will load the root index.html file.
What I want is it to do nothing and execute the onclick handler.

Now I have two possible solutions:

- Replace the # with javascript:... and remove the onclick handler.
- Replace the A HREF by a SPAN having the same style as a link.

Return false in the onclick handler.
Jul 6 '06 #3

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...
3
by: Oliver Saunders | last post by:
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="javascript"> function a(fromlink) {...
0
by: Danny Patricia | last post by:
Hi How I can change this tag in order to works in NET? <a href="#" onclick="MyFolderProfile('<% =sFolder%>'); return false;" onmouseover="return ImageDown ('imgProfile', '<%if...
7
by: Nathan | last post by:
I've been reading a bit about proper ways to use <a> tags to launch javascript functions, but I'm still not clear on one issue. I understand it is common to create a link in HTML such as <a...
6
by: kelvlam | last post by:
Hello, I'm a new begininer with JavaScript. I'm trying to figure out which is the best approach, and to understand the differences between them. I have a <Aelement that's suppose to either...
4
by: jodleren | last post by:
Hi all I have a file I open in a smaller window, like this: <a href="#" onclick="window.open.... but it also causes the main window to jump to the top. What have people done to avoid that?...
5
by: Maria Sudderman | last post by:
I have a prblem with the "onClick" command. onClick="insert('<a href="URI">', '</a>')"> but this is not correct! why? Maria
5
by: dangt85 | last post by:
Hello, I have the following page: ... <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
1
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
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...
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,...
1
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...
0
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...
0
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 ...

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.