Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
jQuery preventdefault
Play lesson

jQuery tutorial for beginners - jQuery preventdefault

5.0 (2)
25 learners

What you'll learn

This course includes

  • 22.5 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

Link for all dot net and sql server video tutorial playlists https://www.youtube.com/user/kudvenkat/playlists?sort=dd&view=1 Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2015/05/jquery-preventdefault.html Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help. https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1 In this video we will discuss how to prevent browser default action using jQuery. First let's look at some of the browser default actions. For example, 1. When you right click on a web page, the browser displays the context menu 2. When you click on a link, the browser navigates to the page specified in the link In some situations you may want to prevent these default actions of the browser. For example some of the websites prevent you from right clicking on the page. Disabling right click is annoying users. Many people say they disabled right click for security, because they do not want their content to be copied. But if you disable JavaScript in the browser, you will still be able to right click and copy the content. So you are achieving nothing by disabling right click. Having said that, now let us see how to prevent the context menu from appearing when you right click on the web page. We discussed how to achieve this using raw JavaScript in Part 43 of JavaScript Tutorial. Let us now discuss, how to achieve this using jQuery Replace < with LESSTHAN symbol and > with GREATERTHAN symbol <html> <head> <title></title> <script src="jquery-1.11.2.js"></script> <script type="text/javascript"> $(document).ready(function () { $(this).on('contextmenu', function (e) { e.preventDefault(); $('#divResult').append('Right click disabled<br/>') }); }); </script> </head> <body style="font-family:Arial"> <h3> Right click disabled on this page. Try to right click and see what happens </h3> <div id="divResult"></div> </body> </html> When you click on a link, how to prevent the browser from navigating to the page specified in the link. <html> <head> <title></title> <script src="jquery-1.11.2.js"></script> <script type="text/javascript"> $(document).ready(function () { $('#myHyperLink').on('click', function (e) { e.preventDefault(); $('#divResult').append('Hyperlink default action prevented<br/>') }); }); </script> </head> <body style="font-family:Arial"> <a id="myHyperLink" href="http://pragimtech.com"> Clicking on the link will not take you to PragimTech </a> <br /><br /> <div id="divResult"></div> </body> </html>

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere