Désactiver un lien en javascript avec jQuery

Avril 2013

jQuery permet de désactiver un lien hypertexte (tag <a>), c'est-à-dire que le clic sur le lien n'a plus aucun effet, la page cible du lien ne s'ouvre pas.

Pour cela, il suffit de sélectionner le ou les liens avec un sélecteur et de placer un event.preventDefault, comme ça :

$('body a').click(function(event){
	event.preventDefault();
});

Cet exemple désactive tous les liens de la page.

Le preventDefault permet comme son nom d'indique d'empêcher le comportement par défaut (ouverture de l'URL du lien) de se produire. Mais les handler javascript associés à l'élément seront quand même appelés. Pour les empêcher également, voir stopPropagation.

Après avoir lu versionning de fichier excel vous en saurez d'avantage sur ce sujet.

Désactiver un lien en Javascript

On peut aussi désactiver un lien sans utiliser jQuery, simplement en faisant un return false sur l'événement click du lien :

<a href="http://www.google.fr/" onclick="return false;">Un lien</a>

Découvrez ce tutoriel photoshop : la classification vox-atypi à lire tout de suite !

4 commentaires :
commentaire n°3470 par Forever
Forever dimanche 12 mars 2017, 01:00
Merciiii!
ça faisait un moment que je recherchais comment le faire ^^
commentaire n°4148 par jameser239@gmail.com
jameser239@gmail.com mercredi 26 juin 2019, 16:56
Great Work From Your Home Business Advice For Busy Lifestyles

Most people have entertained the idea of being their own personal boss. Undoubtedly, it has crossed your brain as well. Being your personal boss and setting your schedule is a superb thing. Read on this post if you wish some strong, effective advice on starting a house business enterprise.

All of your efforts ought to keep your home business customers happy. It is much easier to generate income from repeat buyers than to attract new ones. Happy customers will come back to get more.

Set up a distinction between work and personal time by creating a set schedule of labor hours. Determine an ending time for each workday. Be sure to schedule plenty of time for the loved friends and ones and for your very own interests.

It is essential to invest in some business card printing. There are a few Web sites where you could get business cards for free. Make sure to include information including your name, business name and telephone number. Don't forget to include your email and website addresses. Having all this information will make it much simpler for customers and clients to get hold of your small business in how that they can feel most comfortable.

Make an effort to offer incentives, which can build your credibility to your customers. People getting the news out about your business is an excellent way to promote your small business. Loyalty is built through incentives, too.

In the event you possess artistic ability, maybe a graphic design organization is for you. Designing for businesses is very profitable, especially if you have the skills. When you purchase this niche, you will certainly be more competitive than larger companies.

To totally tap into the your internet business potential, you want to search on the internet to advertise it. Ensure that the strategies you employ work well. Blogs, content creation, forums, and emails are all efficient ways to get your business more visibility at no cost, ultimately causing more visitors.

If you're having a daycare from your own home, particularly if you have lots of kids, make sure you have enough help. Without enough help, it will likely be difficult to properly maintain your kids.

Ensure your web business won't affect your family's routine. It may be necessary to adjust your plans when you discover that your intended business is disruptive to the mode of living.

Whenever you get a payment, use it from the bank. As an alternative to creating a weekly or monthly bank deposit, make deposits daily or weekly. If you don't deposit a check right away, it could go missing. Work with a teller to deposit your money through, as opposed to an ATM, to be certain the cash explores your money.

When you have just learned, there are lots of people trying to sell you on scams. However, as you've learned throughout this informative article, there are also many common-sense tips and tactics that you can use to be able to expand your home based business. If you're ready to make the work, you may certainly be successful.


https://thetrueone1.blogspot.com/2019/06/oody-geffen_2.html


oody
commentaire n°5049 par dev_ia
dev_ia mardi 12 mai 2020, 19:38
Bonjour, avec onclick="return false"; ca fonctionne très bien, par contre en version
mobile impossible d'ouvrir ce liens y'a t-il une methode pour la désactiver en passant en version mobile ?
commentaire n°7138 par Herman
Herman mardi 15 juin 2021, 17:00
Bien bien
facultatif
Facebook Twitter RSS Email
Forum Excel
Venez découvrir le nouveau forum excel question/réponse à la stackoverflow.com !
Forum Excel
hit parade n'en a rien a foutre du W3C Positionnement et Statistiques Gratuites Vincent Paré