Dysan Posted April 14, 2008 Share Posted April 14, 2008 Hi, If JavaScript is turned ON!: Using JavaScript, how do I display a div upon a link being clicked? If JavaScript is OFF! How do I navigate to a different page upon the link being clicked? Go here for example: http://codenewbie.com/forum/ - Click the "Search" button near top-right of page! Cheers Quote Link to comment Share on other sites More sharing options...
haku Posted April 15, 2008 Share Posted April 15, 2008 First, create a link and set the href to be the page you want to navigate to if javascript is turned off. Also give it an ID. <a href="no_javascript.page" id="target_link">link</a> Then you target that link with javascript. I put this in an external file: function setLinkListener() { var target = document.getElementbyId("target_link") target.onclick = function() { // set the details of what you want to happen when the link is clicked // and javascript is on return false } } window.onload = function() { setLinkListener() } What this does is first defines a function that finds the link in question using the ID that the link was given. After it has found that link, it listens for it to be clicked. If it is clicked, then the code is executed, and returns false. By returning false, the page will not advance to the href value in the <a > tag, and only the javascript will be executed. Finally I set that function to be run once the page is loaded using window.onload. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.