Jump to content

JavaScript Div/Non JavaScript Page


Dysan

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.