使用javascript改进链接
摘自《javascript基础教程》
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to our site</title>
<script src="script002.js"></script>
</head>
<body>
<h2 class="centered">Hey,check out <a href="http://www.pixel.mu/" id="redirect">my cat's web site</a></h2>
</body>
</html>
script002.js
// JavaScript Document
window.onload = initAll;
function initAll() {
document.getElementById("redirect").onclick = initRedirect;
}
function initRedirect() {
alert("We are not response for the content of pages outside our site");
window.location = this;
return false;
}