<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
Related
Add custom confirm message to standard joomla 3.0 admin toolbar button.
I can get alert messages on delete when I don't selected any check boxes on detailed list.
I can get same on any button by set last parameter true in
JToolBarHelper::custom('userdetails.sendMail', 'mail.png', 'mail_f2.png', 'Send Mail', false);
I want to add a confirm message on the click event of this Button?
On view file (tpl/view file name).
<script type="text/javascript">
Joomla.submitbutton = function(task)
{
if (task == 'userdetails.sendMail')
{
if (confirm(Joomla.JText._('Do you really want to send mails to selected users?'))) {
Joomla.submitform(task);
} else {
return false;
}
}
}
</script>
Just as an addition to Suman Singh's answer, you may want to include the script in the document header, and also be able to translate the confirmation text. So, in your layout file, you can write:
$document = JFactory::getDocument();
$document->addScriptDeclaration('
Joomla.submitbutton = function(task) {
if (task == "userdetails.sendMail") {
if (confirm(Joomla.JText._("COM_YOURCOMPONENT_USERDETAILS_SENDMAIL_CONFIRMATION_TEXT"))) {
Joomla.submitform(task);
} else {
return false;
}
}
}
');
JText::script('COM_YOURCOMPONENT_USERDETAILS_SENDMAIL_CONFIRMATION_TEXT');
And of course in the language/en-GB/en-GB.com_yourcomponent.ini file:
COM_YOURCOMPONENT_USERDETAILS_SENDMAIL_CONFIRMATION_TEXT="Are you sure you want to send mails to the selected users?"
In my program, if a user tries to leave a page, he'll receive a dialog box asking if he is sure he wants to leave.
How should I implement the 'cancel' option if the user chooses not to leave the page?
Source javascript code:
$(window).unload(function(){
var c= confirm ("Are you sure?");
if (c){
alert("Thanks. Good luck!");
}
else{
????
}
});
window.onbeforeunload = function() {
return 'You have unsaved changes!';
}
many question about this in stackoverflow
How can I override the OnBeforeUnload dialog and replace it with my own?
JavaScript + onbeforeunload
jQuery(window).on('beforeunload',function(){
var value = navigateAway(isDirty);
if(value=="changed")`enter code here`
{
if(jQuery("#saveCheck").val()=="false")
{
return "<?php echo JText::_('OVR_WANT_TO_LEAVE');?>";
}
}
});
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.
Once user presses refresh or browser back button,then I want to redirect the user to one of the page for restart the application.My javaScript code is as follow:
var workIsDone = false;
window.onbeforeunload =confirmBrowseAway;
function confirmBrowseAway()
{
if (!workIsDone) {
alert("You are moving to choice page");
window.location.href="/choice_page/";
}
}
function abc(){
workIsDone=true;
}
//.
//.
<div align="center"><input class="button blue" type="Submit" value="Next" onClick="abc()"></div>
But I don't know why it is not working. I don't want to use confirm box.
Followup:
I have updated the code a bit. Its taking the user to choice page and asking to remain on the choice page or carry on with the work. But when user click OK to carry on the work, the last submitted data is again submitted.
function confirmBrowseAway()
{
if (!workIsDone) {
window.location.href="/choice_page/";
return "Since you pressed refresh or back button, you are on start page again.";
}
}
You could try this, but it only works in IE (ie8 that I tested):
<script language="javascript">
function document.onkeydown() {
if (event.keyCode == 116) {
alert("MOVING AWAY");
window.location.href="/choice_page/";
event.keyCode = 0;
event.cancelBubble = true;
return false; }
}
</script>
Here is how to detect the refresh
Doing some here and there changes in the solution window.onbeforeunload may fire multiple times worked for me.
Thank you all,
Sunil Chauhan
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>