Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

AJAX but accessible links

, 15 Nov 2006
A JavaScript tip to make on the same HTML link a JavaScript call or a classic navigate for a new tab/ new window/ disabled JavaScript tool.
ajaxaccessibleslink_src.zip
<script type="text/javascript">

function SmartLink(evt, sender, ajaxJs)
{
var ctrlid = sender.id;
var ctrlhref = sender.href;
sender.href='';
var btn = evt.button;
var IE=navigator.appName=='Microsoft Internet Explorer';
if(!IE){ btn ++ ;} 
var classic = false;
if((btn < 2) && (!evt.ctrlKey) && (!evt.shiftKey))
{
eval(ajaxJs);
setTimeout("SmartLinkRestaureHref('"+ctrlid+"', '"+ctrlhref+"')",1);
}
else
{
sender.href=ctrlhref;
}
return false;
}

function SmartLinkRestaureHref(cid, url)
{
document.getElementById(cid).href = url;
}
</script>
<!-- [/reusable functions] -->
<script type="text/javascript">
function MyAjaxLink1()
{
// my ajax method
alert('i can make a ajax call here');
}
</script>

<a id="SmartLink1" href="http://www.google.com" onclick="SmartLink(event, this, 'MyAjaxLink1()');">my smart link 1</a>
<ul>
<li>a simple click on the link : javascript call</li>
<li>a simple click on the link without javascript : classic navigate</li>
<li>open the link on the a new tab/ new window : switch to classic navigate</li>
</ul>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

seubi
Web Developer
France France
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 15 Nov 2006
Article Copyright 2006 by seubi
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid