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

Home Posts Topics Members FAQ

javascript in anchor tags

If using an onclick event handler to execute javascript when an anchor
element is clicked on, what should the href attribute be? #?
javascript:void (0)? Something else?

Sep 5 '05
11 12598
Stephen Chalmers said the following on 9/7/2005 5:26 PM:
Donius <ra************ **@gmail.com> wrote in message news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
So for those users without javascript, it
doesn't have a chance to return false ((since none of the script will
run at all)), and will "fall through" and do the hyperlink action.

In compliant browsers, that situation can be alleviated by setting the href to the name of an anchor placed at the top
of the body element, like:

<BODY>
<A name='screenTop ' style="position :fixed;top:0;vi sibility:hidden ">.</A>
....

Then for relevant links: <A href='#screenTo p' ...

The position of the anchor will always be the current scrolled position, so if the href has to be followed, the page
does not scroll.


You can create the same effect, and have it work in IE, by adding an
Anchor before/after each link.

<a name="thisLink" >
<a href="#thisLink ">.....</a>

But better is to have JS create links/buttons that are JS dependent.
Then, the non-JS people never know it doesn't work because they never
see it.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 7 '05 #11
Randy Webb <Hi************ @aol.com> wrote in message news:Hd******** ************@co mcast.com...
Stephen Chalmers said the following on 9/7/2005 5:26 PM:
Donius <ra************ **@gmail.com> wrote in message news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
So for those users without javascript, it
doesn't have a chance to return false ((since none of the script will
run at all)), and will "fall through" and do the hyperlink action.

In compliant browsers, that situation can be alleviated by setting the href to the name of an anchor placed at the top of the body element, like:

<BODY>
<A name='screenTop ' style="position :fixed;top:0;vi sibility:hidden ">.</A>
....

Then for relevant links: <A href='#screenTo p' ...

The position of the anchor will always be the current scrolled position, so if the href has to be followed, the page
does not scroll.


You can create the same effect, and have it work in IE, by adding an
Anchor before/after each link.

<a name="thisLink" >
<a href="#thisLink ">.....</a>


It's not quite the same effect, as the page scrolls to position the target anchor at the top of the screen.

You don't need a separate anchor, the link can refer to itself:

<a name='thisLink' href="#thisLink ">.....</a>

--
S.C.

Sep 8 '05 #12

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

Similar topics

12
6613
by: CJM | last post by:
Is it possible to achieve a hover effect for a non-anchor tag in CSS? I can use the following code, but it goes against the grain: <a href="" onclick="return false;">Label</a> Surely there must be a 'proper' way of doing it? Thanks Chris
5
4622
by: TS | last post by:
is there a way to force all links on a page to open in a new browser window without declaring them with a target=_blank attribute? some kind of global thing? I thought i saw it in a stylesheet once, but can't find it now. thanks
3
2650
by: DC | last post by:
Given: a { text-decoration:none; } a:hover { text-decoration:underline; }
1
5734
by: newcreation | last post by:
I call this a weird problem because I can't find anything on it over the internet. Whenever I try to put in an anchor tag within a paragraph, the anchor forces a line break and appears on the next line. I have two sentences in a row with anchor tags, and the anchors appear on the web page one on top of the other. You can see it here: www.supportsingleparents.net/estore.htm If you look at my page source, you'll be able to see where the...
2
1594
by: drabbas | last post by:
http://www.shaneregister.com/listings.asp#15 The following page has anchor tags setup that will link you to the listing. This works fine in firefox. In IE it does not work at all. You can veiw source to see the code. Any help would be appreciated. Thanks
5
10584
by: smita232 | last post by:
HI , i have a code : <a href="#" >Hyperlink</a> Now how do i remove the anchor tag dynamically using Javascript?
8
5135
by: azjudd | last post by:
Thank you in advance for your help on this one. I'm using named anchor tags on a FAQ page with questions listed at the top and answers below; a standard jump-to feature. However, anytime an anchor tag link is used, whether it be a question down to an answer or an answer back to the list of questions, I lose the banner div, a good portion of of my MenuDv disappears, and white space is added to the bottom of my page. You can see my FAQ page...
0
1217
gautamrohit23
by: gautamrohit23 | last post by:
Hello All, i am using repeater to generate the anchor tags <ItemTemplate> <tr> <td><a href="<%#Eval("Word_Link")%>" title="<%# Eval("Word_NAME") %>" target="_blank"><%# DataBinder.Eval(Container.DataItem,"Word_NAME") %></a></td> </tr> </ItemTemplate> i am getting Some anchor tags , but i want to change the font size of the anchor tags(like tag cloud) .
0
8609
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
9031
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...
0
7739
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
6528
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
5862
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
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
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.