Progressive enhancement and smooth degradation of javascript

  • 2020-03-29 23:41:37
  • OfStack

How to implement this function like Google?


<script type="text/javascript">
 function displayMenu() {
    //Display navigation list;
 }
 </script>
 <a href=" The target page " onclick="displayMenu(); return false;"> More and more »</a>

Explanation: displayMenu() is a function that displays a navigation list (omitting its implementation because that's not what we're talking about)
Onclick specifies the click event for the link.
Return false: cancels the default behavior of the browser (so that displayMenu() is executed without the page jumping).


<!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> Another way to open a link in a new window </title>
<script type="text/javascript">
function popup(url) { window.open(url); }
</script>
</head>
<body>
<ul>
    <li><a href="http://www.baidu.com/" onclick="popup(this.href); return false;"> baidu </a></li>
    <li><a href="http://www.google.com.hk/" onclick="popup(this.href); return false;">google</a></li>
</ul>
</body>
</html>


Related articles: