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
I wrote a jsp page today. I tried to adjust <di...
Four network types: None: Do not configure any ne...
This article shares the specific code of jQuery t...
This article shares the specific code for impleme...
Background: Linux server file upload and download...
statement : This article teaches you how to imple...
question When installing Docker using Alibaba Clo...
This article shares the specific code of JavaScri...
question I encountered a problem when writing dat...
Recently I used MySQL to export table data to an ...
I wonder if you have ever thought about this ques...
Table of contents in conclusion Practice Analysis...
Preface The method of configuring IP addresses in...
The tee command is mainly used to output to stand...
1. Add skip-grant-tables to the my.ini file and r...