Disable link to current page number. (anchor tag)

I have one anchor tag. I want to unplug it after it clicked. I tried as follows.

print "<script type='text/javascript'>parent.window.frames[2].document.getElementById('pagination').innerHTML+=\"<a href=# onclick='pageshow`($i);this.disabled=true'>$i</a>&nbsp;\"</script>"; 

Note: I do not want to disable the link. I want to disable the communication operation. Like a Google search page.

For example: 1 2 3 4 5 Next

Here, when I clicked the first page, I cannot click the same page again. The same thing I want.

+4
source share
5 answers

You can also disable the anchor tag using the following method.

 <a href='URL' style='text-decoration:none;cursor: auto;' onClick='return false'>LINK</a> 
+7
source

After rereading the question ...

Google does not disable the link after clicking it.

They simply do not link to the current page. Their markup is horrific, so I won’t copy it, a simplified example (on page 2):

 <ol> <li><a>1</a></li> <li>2</li> <li><a>3</a></li> <li><a>4</a></li> </ol> 
+3
source

The best answer I've seen in this question includes using jQuery.

How to enable or disable binding using jQuery?

here the code breaks the link. This disables <a id="current"> , preventing e (click event at anchor)

 $(document).ready(function() { $('a#current').click(function(e) { e.preventDefault(); }); }); 
+2
source
 <a href="…" onclick="this.removeAttribute('href');"> 
+1
source

Javascript is the wrong way to do this, but I will give you the answer to this question:

 var links = document.getElementsByTagName('a'), link, children; for(var i = 0; i < links.length; i++) { link = links[i]; if(link.href == window.location.href) { children = link.childNodes; for(var j = 0; j < children.length; j++) { link.parentNode.insertBefore(children[j], link); } link.parentNode.removeChild(link); } } 

Edit: I don't know if the “he-two-hockey-sticks” is a “dirty language” on SO, but if so, it will be mysteriously removed after a few months, so I used “heck” instead.

0
source

Source: https://habr.com/ru/post/1305294/


All Articles