Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Preventing browser default action
Play lesson

JavaScript Tutorial - Preventing browser default action

4.0 (0)
13 learners

What you'll learn

This course includes

  • 12.3 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 http://www.youtube.com/user/kudvenkat/playlists Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2015/01/preventing-browser-default-action.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. First let's look at some of the browser default actions. For example, 1. When you click on a link, the browser navigates to the page specified in the link 2. When you right click on a web page, the browser displays the context menu 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. There are 2 ways you can do this. Using oncontextmenu attribute of the body element to disable right click [html] [head] [/head] [body oncontextmenu="return false"] [h1]On this page right click is disabled[/h1] [/body] [/html] Using the event object to disable right click IE 8 and earlier versions event.returnValue = false; IE 9 & later versions and all other browsers event.preventDefault(); [h1]On this page right click is disabled[/h1] [script type="text/javascript"] document.oncontextmenu = disableRightClick; function disableRightClick(event) { event = event || window.event; if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false } } [/script] When you click on a link, how to prevent the browser from navigating to the page specified in the link [a href="http://pragimtech.com" onclick="return false"] Clicking on the link will not take you to PragimTech [/a] OR [a id="linkElement" href="http://pragimtech.com" onclick="preventLinkNavigation(event)"] Clicking on the link will not take you to PragimTech [/a] [script type="text/javascript"] function preventLinkNavigation(event) { event = event || window.event; if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false } } [/script]

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