-
How do I display a JavaScript link if the browser has JavaScript enabled, and yet have non-JavaScript browsers display a basic link to the next page?
Whether the browser has JavaScript enabled or not (or doesn't support it), I want each version of the page to display only their version of the link. That is, display the JavaScript link to JS browsers, and the non-JS link to Non-JS browsers.
One method I know is to set an ID on the non-JS link and use the style.display method to not display it for JS enabled browsers. However, this only works in IE4 and not NS4; and it does not remove the JS link for non-JS browsers.
Anyone have any suggestions? Thanks!
-
Not sure what you mean by a "JavaScript Link". Are you calling a JavaScript function from a link?
-
Yes, a JavaScript function from a link.
The function is just some cookie code that opens up a Subscribe popup, and than refers the user to the link.
The non-JavaScript link just refers them to the link.
-
Hey pale,
would this be kind of what you want:
<script>
document.write('<a href="javascript:dothis()">JavaScript function link</a>');
</script>
<noscript>
<a href="non_javascriptLink.html">JavaScript function link</a>
</noscript>
Hope that helps,
aDog :cool:
-
Yes, that's exactly what I'm looking for. B:)
/me remembers seeing that somewhere at sometime in the future
geesh, if only i coulda remembered ;)
Thanks, Arielladog =)
-
You can also use event handlers -
onsubmit="doThis()"
onMouseOver="doThis()"
onMouseOff="doThis()"
onClick="doThis()"
onChange="doThis()"
-
Here's my favorite method:
<a href="nextpage.html" onClick="myFunction('nextpage.html');return false;">...</a>
The "return false;" in the event handler causes browsers with JavaScript enabled to ignore the href attribute. Meanwhile, JavaScript-incapable browsers will ignore the onClick and treat the tag as a normal link.
Neat and tidy.