Geeks With Blogs
Geekette Mai Blog

A while ago I was asked to performed some sort of action for Acounting group after a user clicks a link, but before the brower loads the new page.  A typical example would be when  you want to put an alert before user goes to a particular page on my application, or it make it clear when the user leaves yoour application

<!DOCTYPE html PUBLIC "_//W3C/DTD XHTML 1.0   Transitional//EN "

   "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<body bgcolor="#FFFFFF">

<scrip type="text/javarscript" src="script09.js"></script>

</head>

<body bgcolor="#FFFFFF">

<h2 align="center">

  Hey, check out <a herf=http://www.pixel.mu/ id="redirect"> my page 2 website</a>

</h2>

</body>

</html>

THE LINK Enhancement script.

 

window.omload = initALL;

function initAll( ) {

         document.getElementbyId( "redirect").onclick = initRedirect;

}

 

function iniTredirect ( ) |

   alert("We are not blah blah blah..."); window.location = this;

return false

}

You may noticed that nowhere in the code does it refer to a mypage 2-- That's part of this power of "this;"

One of the things the "this; " keyword does for us is grab the URL from the HTML link (that is, the value of the a tag's herf attribute).  If I using this approach, I don't have to touch the links ehnamcement script.    I could have links all over our Application Website calling from the same script, and all line of code would automately grab their href values as well.

 

Posted on Monday, February 15, 2010 12:12 PM | Back to top


Comments on this post: Using Javarscript to enhance links

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Mai Nguyen | Powered by: GeeksWithBlogs.net