I my web application I want to Hide/ Remove some for the menus like View Source, Properties using JavaScript coding. This should available in entire webpage.
Do not do it.
You only make your users angry but you can not stop them any way.
See also How do I disable right click on my web page?
If I can't stop you from doing it. You can only disable the whole menu:
<script language="javascript">
document.onmousedown=disableclick;
Function disableclick(e)
{
if(event.button==2)
{
return false;
}
}
</script>
var message="Sorry, right-click has been disabled";
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {
if(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS;
}
else{
document.onmouseup=clickNS;
document.oncontextmenu=clickIE;
}
document.oncontextmenu=new Function("return false")
This is code disable the right click.
Related
In my Android phonegap/Cordova 3.5 project, I have 3 html pages (a button in index.html calls page2.html where there is another button calling page3.html).
In page2.html I override backbutton doing this in deviceReady:
document.addEventListener("backbutton", onBackKeyDown, false);
then
function onBackKeyDown() {
console.log("onBackKeyDown");
navigator.app.exitApp();
}
but in page3.html I want to let Android controlling backbutton so I do not override it in page3.html.
Instead in page3.html backbutton is disabled.
Questions:
Is this the expected behaviour (overriding one means overriding for
ever)?
How to get rid with this? (leave the control of backbutton to
Android anytime I want to)
You can check the page in the OnBackKeyDown event:
function onBackKeyDown() {
var pagename = // get the page name here
if ( pagename == page3.html ) {
history.back();
}
else {
navigator.app.exitApp();
}
}
You can back button behaviour according to each page. Example is shown below.
function onBackKeyDown(e) {
if ($.mobile.activePage[0].id == "home"
|| $.mobile.activePage[0].id == "login") {
e.preventDefault();
navigator.app.exitApp();
}else if($.mobile.activePage[0].id == "inspection"){
e.preventDefault();
back();
//return false;
}else if($.mobile.activePage[0].id == "noDetails"){
e.preventDefault();
$.mobile.changePage("home.html");
return false;
}else{
navigator.app.backHistory();
}
}
I am using jQuery Mobile- gives more control over page transitions.
the real solution to this question is probably to remove the event with this API:
document.removeEventListener("backbutton", onBackKeyDown, false);
I found it here
Just wondering, is it possible to create an alert with multiple options?
Like for example, in Facebook, when you try to close the tab/window when you have not finished typing your message, an alert with the options "Leave this page" and "Stay on this page" will pop up.
Example with form, you'are looking for window.onbeforeunload:
<script type="text/javascript">
var originalFormContent
var checkForChanges = true;
jQuery(document).ready(function () {
originalFormContent = jQuery('#myForm input[type=text]').serialize() + jQuery('#myForm select').serialize();
});
function onClose() {
if (checkForChanges && originalFormContent != "undefined") {
var content = jQuery('#myForm input[type=text]').serialize() + jQuery('#myForm select').serialize();
if (content != originalFormContent) {
return confirm('You have unsaved changes. Click OK if you wish to continue ,click Cancel to return to your form.');
}
}
}
window.onbeforeunload = onClose();
You're referring to window.onbeforeunload:
Best way to detect when a user leaves a web page?
You can also use the window.confirm() function for OK/Cancel options:
http://jsfiddle.net/UFw4k/1
Other than that, you'd have to implement a custom modal alert, such as jQuery Dialog.
Please have a look at http://jqueryui.com/dialog/#default
Copied this from a previous answer: JavaScript alert with 3 buttons
<a href="Profile.aspx?ProfileId=1" class="view-profile">View profile<a>
When the user click on my href there is an treatment=" .ajax script that will allow or the user to view the profile."
the problem is when that when the user right click my href,the treatment is ignored and the user can see the all profiles.
How can I prevent the right click?
Or how can I execute the same treatment(check) when the user right click my href.
I have tested the below code but not working:
$(function() {
$('.view-profile').bind("contextmenu", function(e) {
return false;
});
});
Thanks in advance.
You shouldn't rely on client-side validation to control user privileges, because it can be easily hacked; rather, use both server-side and client-side validation or simply server-side alone.
<script language=JavaScript>
<!--
//Disable right mouse click Script
//By Maximus (maximus#nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com
var message="Function Disabled!";
///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("alert(message);return false")
// -->
</script>
--source: http://www.dynamicdrive.com/dynamicindex9/noright.htm
I want to open a facebox modal after some javascript validation. I am using this code:
<script type="text/javascript" src="facebox.js"></script>
Script:
function validatePage()
{
if(document.getElementById('username').value == '')
{
alert('Please enter Username');
return false;
}
//My Code should go here
}
Markup:
Click Me
For some reason the facebox modal does not open...instread the page is opening in a new window.
Any suggestion will be highly appreciated.
Thanks in advance
Is your onclick overriding the Facebox functionality? I don't know if it would, but that's a thought. Have you tried manually triggering the function instead?
function validatePage(e)
{
if(document.getElementById('username').value == '')
{
alert('Please enter Username');
} else {
$.facebox({ajax: $(e).attr("href")});
}
return false;
}
I just passed the element to the function, to make that extend to other things. You'd just say "javascript:validatePage(this)" in your onclick.
I'm trying to create a alert box which prompts user whether to delete or cancel, when I'm clicking on delete button it is working fine but when I click cancel again my webpage is closed. Below is the enclosed function. Please help.
<SCRIPT language="JavaScript">
<!--
function go_there()
{
var where_to= confirm("Do you really want to go to this page??");
if (where_to== true)
{
//closes the page
}
else
{
//Cancel the page and do not close the page
}
}
//-->
</SCRIPT>
In such cases the most common error might be that you would have omitted
return false
on clicking cancel, it should return false. This might be a plausible solution.
In your case either give a return statement or define an empty function which does nothing.
<SCRIPT language="JavaScript">
<!--
function go_there()
{
if (confirm("Do you really want to go to this page??")) {
//closes the page
} else
return false;
}
//-->
</SCRIPT>
<script language="JavaScript">
<!--
function go_there() {
if(!confirm('Do you really want to go to this page?')) {
return false; //Cancel the page and do not close the page
}
}
-->
</script>