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
Today, I set up a newly purchased Alibaba Cloud E...
Preface Since many friends say they don’t have Ma...
Table of contents 1. How to view the binary data ...
Meta tag function The META tag is a key tag in th...
Scenario simulation: The operation and maintenanc...
The project requirements are: select date and tim...
First: 4 ways to introduce CSS There are four way...
When using MySQL 5.7, you will find that garbled ...
1: Statement order of grouping function 1 SELECT ...
1. Server setup The remote repository is actually...
Table of contents Download tf-gpu Build your own ...
After pressing Enter on the webpage, the form is a...
After creating a container locally, you can creat...
SQL statement DROP TRIGGER IF EXISTS sys_menu_edi...
Table of contents Error message Cause Error demon...