Jump to content

JavaScript link activation


djp1988

Recommended Posts

I have this page: http://www.herpfrance.com/indexTest.phpI was wondering if it was possible to have a code, where if the browser has not activated javascript, the links in the features div would go to a different page to display the latest updates, obs, news and statistics, but i couldn't have this link in the page at the start otherwise the people who have javascript would just be sent off to that page instead of seeing the javascript in action.Maybe some code that detects if JS is active, and if it is not then change the javascript links into links off to other pages ?

Link to comment
Share on other sites

A basic way to do what i believe you're asking is to make each link element something like this:<a href="pageWithoutJs.html" class="special" ref="pageWithJs.html">Link Name Here</a>you're javascript (i use mootools. Download it at mootools.net) would then be

$$('a.special').each(function(item){  item.href = item.getProperty('ref');});

There is no point in detecting if Javascript is enabled, because in order for Javascript to run, it must be enabled, so having JS to detect JS would be silly. If it's on, it will run, if its not, then the user will just go to pageWithoutJS.html when they click the link.

Link to comment
Share on other sites

I think I understand what you want, do you want to execute some javascript when those links are clicked? And when scripts are disabled, let the links direct to a real page instead of executing scripts?If that is the case, this could be something interesting for you:

<a href="jslesspage.php" onclick='yourFunction(); return false;'>Link</a>

Explanation: the link consists of only one valid url, which will be used when scripts are disabled, and, if not, will be bypassed by the "return false" statement that will be called at the end of the onclick event, before the target is loaded :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...