Through JavaScript, we can prevent hyperlinks from jumping. Here’s how: (1) Manipulating the href attribute of a hyperlink Writing method 1: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <a href="javascript:void(0);" rel="external nofollow" >Hyperlink</a> </body> </html> Writing method 2: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <a href="javascript:;" rel="external nofollow" >Hyperlink</a> </body> </html> Clicking the link does not redirect. (2) Default behavior of blocking links Writing method 1: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <a href="https://www.baidu.com" rel="external nofollow" rel="external nofollow" >Baidu</a> <script> var link = document.querySelector("a"); link.addEventListener('click',function(e){ e.preventDefault(); }) </script> </body> </html> Writing method 2: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <a href="https://www.baidu.com" rel="external nofollow" rel="external nofollow" >Baidu</a> <script> var link = document.querySelector("a"); link.onclick = function (e) { return false; } </script> </body> </html> At this time, clicking the hyperlink will not jump. The above is the details of how to use JavaScript to prevent hyperlink jumps (various writing methods). For more information about js hyperlink jumps, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Tutorial on installing Android Studio on Ubuntu 19 and below
>>: Summary of tips for setting the maximum number of connections in MySQL
1. Multiple calls to single arrow Once a single a...
Before talking about the structural markup of web...
Table of contents Preface Introduction JavaScript...
Table of contents Preface What is Hot Change Coco...
The traditional method is to write a square in a ...
Preface When a Linux is fully set up, you can use...
When rendering Markdown before, I used the previe...
Let's first look at several ways to submit a ...
1. Run the .sh file You can run it directly using...
This article example shares with you the specific...
Preface When you install MySQL, you usually creat...
Using the html-webpack-plugin plug-in to start th...
Original : http://developer.yahoo.com/performance...
1. Create a project with vue ui 2. Select basic c...
Data URI Data URI is a scheme defined by RFC 2397...