Javascript that prevents a specific url from loading?
1 answer
I wrote this Jsfiddle for you. Try it with code.
Url: http://jsfiddle.net/Lexjdgme/
HTML:
<a href="http://news.google.com">news.google.com</a><p>
<a href="http://www.google.com">www.google.com</a>
JavaScript:
[].forEach.call(document.getElementsByTagName('a'), function (el) {
el.addEventListener('click', function(e) {
if(e.target.href==="http://news.google.com"){
e.preventDefault();
}
}, false);
});
EDIT:
If you want to remove the link tag, you can do it like this:
// With JQuery
$('.advise').remove();
// Or directly with javascript
var advise= document.querySelector('.advise');
advise.parentNode.removeChild(advise);
Another Jsfiddle: http://jsfiddle.net/Lexjdgme/1/
+2
source to share