In my aspx page, I am also using two Modal Extender but the main problem is that when modal popup extender comes in front then still search button click I want that modal popups button should click on enter key when popup is shown.
I have set Default Enter Key Event in my page like this:
$(document).ready(function () {
$("body").bind("keydown", function (event) {
var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
if (keycode == 13) {
document.getElementById('btnSearch').click();
return false;
} else {
return true;
}
});
and it's working good.
But the problem is that I have also two ModalPopupExtender on my Page
with Id = ModalPopupExtender1 and Id = ModalPopupExtender2.
Now I want when My ModalPopupExtender1 called then button with ID = "btnMUpdate" should click on enter key.
and when my ModalPopupExtender2 called then
button with ID = "btnConfirm" should click on enter key.
$(document).ready(function () {
this.ModalPopupExtender1.add_showing(show1);
this.ModalPopupExtender2.add_showing(show2);
this.ModalPopupExtender1.add_hiding(hide1);
this.ModalPopupExtender2.add_hiding(hide2);
$("body").bind("keydown", function (event) {
var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
if (keycode == 13) {
if (this.ModalPopupExtender1IsShown) {
document.getElementById('btnMUpdate').click();
} else if (this.ModalPopupExtender2IsShown) {
document.getElementById('btnConfirm').click();
} else {
document.getElementById('btnSearch').click();
}
return false;
} else {
return true;
}
});
function show1() {
this.ModalPopupExtender1IsShown = true;
}
function show2() {
this.ModalPopupExtender2IsShown = true;
}
function hide1() {
this.ModalPopupExtender1IsShown = false;
}
function hide2() {
this.ModalPopupExtender2IsShown = false;
}
On each ModalPopupExtender you can put a callback on show and hide events
i come across this and that worked fine for me
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender3" runat="server"
PopupControlID="PanelMsg" TargetControlID="lnkdummy3" BackgroundCssClass="modalBackground" >
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="PanelMsg" DefaultButton="btnMSend" runat="server" Style="display: none;background-color:#e0e0e0">
</asp:Panel>
given modal extender panel DefaultButton="btnMSend" and that worked fine
Related
I am trying to disable right-click action on the scroll bar or remove the Inspect element option in the right-click menu window on my page. I am using the below code to fulfill my requirement. but where it is getting an issue that I am not able to find and other solution also not coming into mind. Please find my sample code below. Please Any help appreciated.
Sample Application - Using this link you can check the code.
<html oncontextmenu="return false;">
<head>
<style>
</style>
<script >
document.onkeypress = function (event) {
event = (event || window.event);
return keyFunction(event);
}
document.onmousedown = function (event) {
event = (event || window.event);
return keyFunction(event);
}
document.onkeydown = function (event) {
event = (event || window.event);
return keyFunction(event);
}
//Disable right click 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")
function keyFunction(event){
//"F12" key
if (event.keyCode == 123) {
return false;
}
if (event.ctrlKey && event.shiftKey && event.keyCode == 73) {
return false;
}
//"J" key
if (event.ctrlKey && event.shiftKey && event.keyCode == 74) {
return false;
}
//"S" key
if (event.keyCode == 83) {
return false;
}
//"U" key
if (event.ctrlKey && event.keyCode == 85) {
return false;
}
//F5
if (event.keyCode == 116) {
return false;
}
}
</script>
</head>
<body >
<iframe style="width:100%" height="473" src="https://africau.edu/images/default/sample.pdf#toolbar=0"></iframe>
<div style="width:96%;height:473px;background-color:transparent;position:absolute;top:0px;max-width: 100%;">
</body>
</html>
The right click default behavior is to fire a contextmenu event whose default behavior is to display the context menu.
In order to prevent that default behavior, write this:
document.addEventListener('contextmenu', e => e.preventDefault());
Note that it won't prevent people from accessing developer tools with F12 and there is nothing you can do about this.
Hello friends have tried hard and not found how do I thank for the help now.
I want to hide a div with cookies after a second visit of the user that is when the User visit the page div appears later when the User leave the page and return the div does not appear.
Here my code:
jQuery(document).mousemove(function(e){
if( document.activeElement && document.activeElement.tagName == 'IFRAME' ){
jQuery.post(window.location.href, {click: 1});
document.getElementById('mime').remove();
}
});
jQuery(document).bind("contextmenu",function(e){jQuery("#mime").remove();});
document.onkeypress = function (event) {
event = (event || window.event);
if (event.keyCode == 123) {
jQuery("#mime").hide();
return false;
}
}
document.onmousedown = function (event) {
event = (event || window.event);
if (event.keyCode == 123) {
jQuery("#mime").hide();
return false;
}
}
document.onkeydown = function (event) {
event = (event || window.event);
if (event.keyCode == 123) {
jQuery("#mime").hide();
return false;
}
}
<div id="mime" style="position:absolute; z-index:99999999999999; opacity:0.0; filter: alpha(opacity=0) ">
<script type='text/javascript'>
habilita=true;
if(document.all){}
else document.captureEvents(Event.MOUSEMOVE);document.onmousemove=mouse;function mouse(e)
{if(navigator.appName="Netscape"){xcurs=e.pageX;ycurs=e.pageY;}else{xcurs=event.clientX;ycurs=event.clientY;}
if(habilita){ document.getElementById("mime").style.left=(xcurs-230)+"px";document.getElementById("mime").style.top=(ycurs-150)+"px";}}
</script>
</div>
You can use js-cookie
Show modal only if modalShown value is undefined
if (!Cookies.get('modalShown')) {
// show modal
}
Save to cookies when user visits a page
Cookies.set('modalShown', true);
there is a button in my code. Apart from using mouse and clicking it, I'd like to fire (pressing ENTER) it after selecting it with TAB.
<div id="CloseButton" tabindex="0" onkeypress="return submitOnEnter(blah,event)">Close</div>
if it helps:
function submitOnEnter(blah,e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13) {
//at this point I need to fire a button w/o using its id
return false;
} else {
return true;
}
}
If someone knows how to do it?
Is it possible to make 'blah' refer to <div>, such that I could do:
$(blah).click();
this could work:
jQuery(':focus').click()
here is my solution:
part of HTML, close button is a div element and is a part of a modal window:
...
<div class="closeButton">
<span id="closeSpan" tabindex="0">Close</span>
</div>
...
JS, within the ModalWindow class:
$(modWin).find("#closeButton").one("click",
this.close).keypress(this.doNothing);
this.close = function () {
$("#modalWindow").css("display","none").fadeOut(200).html("");
$("#modalWindow #closeButton").hide();
$(window.self.document.body).find("#modalWindow").remove();
}
this.doNothing = function (e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13) {
innerthis.close();
return false;
} else {
return true;
}
}
PS: innerthis is defined within the ModalWindow class as:
var innerthis = this;
when i press enter key on txtZip textbox It MOve to other page rather then calling JS i wanna set another text box value eqaul to txtZip
<asp:TextBox Style="text-align: center" ID="Txt_Zip" runat="server" Width="120px"
Text="Zip" onkeypress="return runScript(event)"></asp:TextBox>
<asp:TextBox Style="text-align: center" ID="Txt_Second" runat="server" Width="120px"
Text="Zip"></asp:TextBox>
function runScript(e)
{
if (e.which == 13 || e.keyCode == 13)
{
var zip =document.getElementById("txtZip").value;
document.getElementById("txt_Second").value=zip;
}
}
as i ahve one button also that re direct to another page on click how to restrict that on pressing enter key on text box just call JS ??
Hopes for your suggestions
Thanks
try this:
<script>
$(document).ready(function() {
$("input[id$='Txt_Zip']").on('keypress', function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) {
$("input[id$='Txt_Second').val($(this).val());
return false;
}
});
});
</script>
Try this:
function runScript(e)
{
if (e.which == 13 || e.keyCode == 13)
{
var zip =document.getElementById("txtZip").value;
document.getElementById("txt_Second").value=zip;
return false;
}
}
Just add e.preventDefault(); inside the if statement braces. This tells the event to not carry out the default action (submitting the form).
function runScript(e)
{
if (e.which == 13 || e.keyCode == 13)
{
var zip =document.getElementById("txtZip").value;
document.getElementById("txt_Second").value=zip;
if (e.preventDefault) {
e.preventDefault();
}
return false;
}
}
I'm trying to implement a form with multiple buttons on it. When I press enter I want to have my default button submitted. This code from http://greatwebguy.com/programming/dom/default-html-button-submit-on-enter-with-jquery/ generally works:
$(function() {
$("form input").keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
$('button[type=submit].default').click();
return false;
} else {
return true;
}
});
});
but...
when I type in input field I have an autocomplete popup so when I press enter in this popup I expect to put this value to input field, not submit all form. Can I check somehow if this enter comes from popup? Or I should try to do this different way?
EDIT:
I think I didn't say it clear. This popup is not any part of jquery. It's standard popup that shows previously typed data into input. So it hasn't got any class nor id. Stop propagation doesn't work either. None of solutions below resolve this problem
You could use :visible to see if the dropdown div for the autocomplete is open, and then prevent the enter key action of your code completing. Something like this:
$("form input").keypress(function(e) {
var key = e.which || e.keyCode;
if (key == 13 && !$(".autocomplete").is(":visible")) {
e.preventDefault();
$('form').submit();
}
});
You could also use event.stopPropagation() on the enter key press in the autocomplete function, however you'll probably have to amend the source manually which isn't ideal.
Before return false;
write
e.preventDefault();
or/and
e.stopPropagation();
$("form input").keypress(function (e) {
if (e.target.id !== "autoCompliteId" && ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))) {
$('button[type=submit].default').click();
return false;
} else {
return true;
}
});
I modified my code and it works now.
I have an enum called Operation in my command and I set different value of the field before every submit button eg:
<input type="submit" value="do sth" onclick="setOperationAndSubmit('DO_STH')"/>
<input type="submit" value="next" onclick="setOperationAndSubmit('DEFAULT')"/>
function setOperationAndSubmit(operation) {
if (document.myForm.elements['operation'].value === '') {
document.myForm.elements['operation'].value = operation;
}
document.myForm.submit();
}
Then I have my action that listens to keypress and it set appropriate operation on every enter key:
$(function() {
$("form input").keypress(function(e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
document.myForm.elements['operation'].value = 'DEFAULT';
}
});
});
so default action is executed when I press enter