Javascript and links in IE6

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
sweahe
Forum Commoner
Posts: 52
Joined: Sat May 04, 2002 4:07 am
Location: Växjö, Sweden

Javascript and links in IE6

Post by sweahe »

Hi!

I thought I could just write a link that calls some javascript and
make it NOT execute the HREF="#" like this:
<a href="#" onclick="toggleOnOff('picture1'); return false">Klick here</a>

This works perfectly (as usual) in Mozilla 1.1, but not in IE 6, where the
page scrolls back up to the top! Why??? Is there a way to avoid this in IE?

/Andreas
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

i believe that is an IE problem that cannot be circumvented. but alas i don't know the JS DOM so i shall defer to anyone elses take on it.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<a href="javascript:void(0)" onclick="toggleOnOff('picture1'); return false">Klick here</a>
someone might show me where <a href="#"> --> do nothing is specified
sweahe
Forum Commoner
Posts: 52
Joined: Sat May 04, 2002 4:07 am
Location: Växjö, Sweden

Post by sweahe »

That worked, but not if the user is holding down shift when clicking...

For more info about links and javascript, look here:
http://www.evolt.org/article/rating/17/20938/index.html

It's the 'return false' that should make it stop running the HREF...

(IE is a buggy one...)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please excuse me not seeing http://www.evolt.org as authoritative when it comes to html, I thought more of w3.org or similar ;)

Why do you use an uri-anchor (href="..." ) if you do not want to link something?
sweahe
Forum Commoner
Posts: 52
Joined: Sat May 04, 2002 4:07 am
Location: Växjö, Sweden

Post by sweahe »

One strange thing... tried the link in IE5 today and it worked, the page wasn't scrolled to the top! A step back in IE 6 or..?

Why? I guess you can't have a link <a...> without a href attribute or..?

Anyway I made my link work both with javascript enabled browsers and without.

/Andreas
sweahe
Forum Commoner
Posts: 52
Joined: Sat May 04, 2002 4:07 am
Location: Växjö, Sweden

Post by sweahe »

Strange... just discovered that it works perfectly in IE6 on another computer? Same version of browser???? OK... forget it! =)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

volka wrote:please excuse me not seeing http://www.evolt.org as authoritative when it comes to html, I thought more of w3.org or similar ;)

Why do you use an uri-anchor (href="..." ) if you do not want to link something?
Have you read the evolt article? The guy who wrote it would agree with you since it is mainly focused on accessibility issues.

sweahe - you really need to find a better way of doing this than with a link that's not a link.

Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Have you read the evolt article?
:oops: no I didn't. In some way (I can't figure) evolt-articles temper with my font settings (sets default to smallest font).
The guy who wrote it would agree with you since it is mainly focused on accessibility issues
well then....no...it still stands "not authoritative" Image
:wink:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

volka wrote:well then....no...it still stands "not authoritative"
It's an article on creating accessible links using Javascript, ie. making it so that non JS users don't lose out because of poorly designed links and forms, it's full of suggestions but at no point does it claim to be authoritative :roll: .

Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

just wanted to emphasise my obstinate bullhead again Image
sweahe
Forum Commoner
Posts: 52
Joined: Sat May 04, 2002 4:07 am
Location: Växjö, Sweden

Post by sweahe »

sweahe - you really need to find a better way of doing this than with a link that's not a link.
Well, now it's a link... working perfectly with or without javascript.
..and somehow it seems like it's just my IE6 that can't handle return false!??
(so I don't care)
Post Reply