Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there an alternative to javascript:void(0)? 1

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
Hi,

I've a link on my page as follows:

<a href='javascript:void(0)' onclick=&quot;openImg('./aguilera81024x768.jpg')&quot;>

Obviously this triggers the javascript to open the image, but when you float over the link it says 'javascript:void(0)' on the status bar.

Not for the first time a user has emailed me saying that when they float over the link it 'appears' to indicate that clicking the link will do nothing, which is understandable as that's what void means.

Can I make this a bit neater, so maybe when you float over the link it says 'Click to open' but still does the same thing as javascript:void(0)? I tried using href='#' which is prettier but it reloads the page.


- Andy
_______________________________
&quot;On a clear disk you can seek forever&quot;
 
to keep from &quot;reloading&quot;:
<a href=&quot;#&quot; onclick=&quot;openImg('./aguilera81024x768.jpg'); return false;&quot;>



=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Thanks jeff, accept a pentangle.

- Andy
_______________________________
&quot;On a clear disk you can seek forever&quot;
 
To extend on jemminger's idea:
Code:
<a href=&quot;aguilera81024x768.jpg&quot; onclick=&quot;openImg('./aguilera81024x768.jpg'); return false;&quot;>aguilera pic at 1024 x 768</a>

If you have javascript on, it opens in popup. If it's off, it works like a normal link. And for both groups, the image name appears in the status bar, so it's a bit of a win-win.

Sounds like an &quot;interesting&quot; website btw ;-)

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
(and you might put title=&quot;opens in popup window&quot; in the <a href..> tag too if you are feeling kind [spin2])

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Hi Clarkin,

Thanks, I'll try those out.

If you want to visit the site, it's :)


- Andy
_______________________________
&quot;On a clear disk you can seek forever&quot;
 
Why not take it a step further and throw in a target attribute so it'll still open in a new window even if JavaScript is disabled?

<a href=&quot;aguilera81024x768.jpg&quot; onclick=&quot;openImg('./aguilera81024x768.jpg'); return false;&quot; target=&quot;_blank&quot;>aguilera pic at 1024 x 768</a>

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life--};
 
:-(

If you do that you've gone to far IMO. Most folks are capable of making the decision to click vs right-click and choose open in new window.


Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
clarkin,
Too far? I understand that the user normally has the ability to click or right-click to open in a new window, but if the designer of the site intended the link to open in a new window in the first place, then what's the matter with making it fool-proof? The whole purpose of a pop-up window is for it to &quot;pop up&quot;, is it not?

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life--};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top