Skip to content

Instantly share code, notes, and snippets.

@kahlil
Created September 17, 2010 14:14
Show Gist options
  • Save kahlil/584287 to your computer and use it in GitHub Desktop.
Save kahlil/584287 to your computer and use it in GitHub Desktop.
/* From http://social.msdn.microsoft.com/forums/en-US/iewebdevelopment/thread/e153eeef-e93f-42e5-a21c-8096bf209688/
For my website I created a "hack" which still has the desired functionality, that is, links are still followed if Javascript is unavailable or disabled and not if javascript does work: */
function myfalse (el) {
if ( navigator.appVersion.match("MSIE 7") ) {
el.href = "java"+"script:;";
}
return false;
}
function myconfirm (msg,el) {
if ( navigator.appVersion.match("MSIE 7") ) {
if ( !confirm(msg) ) {
if ( !el.oldhref ) { el.oldhref = el.href; }
el.href = "java"+"script:;";
}
else {
if ( el.oldhref ) { el.href = el.oldhref; }
}
}
else {
return confirm(msg);
}
}
/* myfalse behaves the same as <a href="link" onclick="return false"> but is used as follows:
<a href="link" onlick="return myfalse(this)">
For browsers such as IE6, Firefox or Opera this will just act as normal, but if the user agent is IE7 then href is set to ;" but this will not matter as javascript is working and the desired javascript functionality will handle the onclick event.
myconfirm is for when you want to create a confirm popup, used as follows:
<a href="link" onclick="return myconfirm('Question', this)">
This will again set the href of the link to ;" if the response is false and the browser is IE7, but it will also set a new property "oldhref" to the actual link, so if the user clicks the link again and the response to the confirm is true, then the old href can be found again.
This is what I use to combat this problem and it seems to work. Hope this helps. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment