I just have a question about how to use ajax or jquery to control stop(esc) in browser url section. This is because some data is very large so it will take very long time to wait. If user does not want to wait he can click stop(esc) in url(it was "refresh" before). The user click stop button "X" then html page will do some event. Could you tell me how to manipulate? Does it has API that I can use directly? Thank you very much!
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
//Do something
}
Related
I have a web application that uses a lot of text input. In some cases it's form input and a Submit / POST action and in others the input text is processed using JavaScript / Ajax.
If I begin typing into, for example, a textarea and then switch to another window (e.g. Outlook) to copy some content to the clipboard, and then switch back to the browser to paste it, the textarea no longer accepts keyboard input.
This only appears to happen on my Windows 10 Pro laptop. On Mac OS it works fine.
I've used multiple browsers.
Is there something in the Windows setup that disables form input as a security measure?
Here is an example of a form declaration in the markup:
<form method="post" action="<?php echo __SITE_URL; ?>admin/_editcandidate.php" autocomplete="off">
I don't use any JavaScript events that are triggered when the focus changes.
Appreciate any insights.
I'm not sure this adds any value to anyone other than it's worth double checking your code for rogue event handlers.
I found this buried in an included file:
window.addEventListener('keyup', function(evt) { keyboardUp(evt); }, false);
and the associated function had a scenario where it could return false:
function keyboardUp(e)
{
var key;
if (window.event) // IE
{
key = e.keyCode;
}
else if(e.which)
{
key = e.which;
}
if (key === 18 && g.altkey === false) { g.altkey = true; return; }
if (g.altkey === false) return;
...
}
Pretty sloppy on my part.
Not sure why this should be an issue switching focus but it does at least solve my problem.
I've got the following setup:
a button which says: "upload your file here", which is just a plain <input type="file" multiple>
When the user goes into finder and wants to drop the file, I want to show a larger area where they can drop the file, since the button isn't very big. This should only be available when the user hovers over the 'bigger input' AND is holding a file.
How do I go about implementing #2?
I have seen a stylechange on this site: http://www.dropzonejs.com/ when the user 'hovers with a file' above the upload area, but haven't been able to figure out how they do it.
Bind a function to the eventtype you want to listen to (dragover, dragenter, dragstart, dragend and dragleave) and make sure this function has at least one argument (the event). Then use event.dataTransfer. Without more details of how you want to implement it, giving example code is hard.
Reference: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer
FYI the dropzonejs you mentioned uses:
return function(e) {
var efct;
try {
efct = e.dataTransfer.effectAllowed;
} catch (_error) {}
e.dataTransfer.dropEffect = 'move' === efct || 'linkMove' === efct ? 'move' : 'copy';
noPropagation(e);
return _this.emit("dragover", e);
}
Above code was bound to "dragover"
You can use Javascript for File Drop Style Change :
check this Example :
// file drag hover
function FileDragHover(e) {
e.stopPropagation();
e.preventDefault();
e.target.className = (e.type == "dragover" ? "hover" : "");
}
I created an HTML page and now would like to hide the source code and encrypt it.
How can I do that?
You can disable the right click, but that's a bad idea because expert minds can read anything from your page.
You cannot totally hide the page source - this is not possible. Nothing is secure enough on the Internet.
In any case, you can encrypt it and set a password.
You can utilise this link - it will encrypt your HTML page with a password.
First up, disable the right click, by writing out this script, right after the tag.
<SCRIPT language=JavaScript>
<!-- http://www.spacegun.co.uk -->
var message = "function disabled";
function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }
document.onmousedown = rtclickcheck;
</SCRIPT>
Then, encrypt all of it, in this website, called 'AES encryption'.
Link - http://aesencryption.net/
You need to set a password to decrypt it ....you choose the password.
After encrypting it, you can just write a basic HTML page just putting into the <head> tag once again the script to disable the right click, into the <body> tag you code and hide everything just writing at top of the page <html hidden>.
Example
<!DOCTYPE html>
<html hidden>
<head>
<SCRIPT language=JavaScript>
<!-- http://www.spacegun.co.uk -->
var message = "function disabled";
function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }
document.onmousedown = rtclickcheck;
</SCRIPT>
</head>
<body>
--here, you put the encrypted code from the link above--
</body>
</html>
Where it is written var message = "function disabled"; you can write for example something like 'This page cannot be viewed' or something which will annoy most of the users and will just leave. ['This page is unavailable' and so on ....].
Finally, you will see a blank page with a message coming up as soon as you right click the page. The message will be something like 'This page is no longer active'.
Example
<SCRIPT language=JavaScript>
<!-- http://www.spacegun.co.uk -->
var message = "**This page is no longer active**";
function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }
document.onmousedown = rtclickcheck;
</SCRIPT>
I do know that one can remove the <html hidden> or the Javascript script with some add-ons such as Firebug but anyway you will need to decrypt the code with a password in order to see the real page.
Expert users might view the source code with a Brute Force attack, I think.
So, nothing is safe.
I found out an application that you need to instal on your computer.
There is a feature in the Enterprise version but you must pay to get it. This feature is a tool which encrypt your HTML page creating an ultra-strong password encryption for HTML files using up to 384 bit keys for encryption [the link I wrote above uses up to 256 bit keys for encryption].
I have never tried it out, though, because it is not for free.
Anyway, the link of the software 'HTML Guardian' - http://www.protware.com/default.htm
For the feature about the encryption, merely click on 'Ultra-Strong HTML password protection' in the page.
You cannot hide the source code, but you can add some difficulties to see your source code by following way
1. Disable right-click:
<body oncontextmenu="return false">
2.Disable ctrl, u, F12 keys:
<script type="text/javascript">
function mousehandler(e) {
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if ((eventbutton == 2) || (eventbutton == 3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
function disableCtrlKeyCombination(e) {
var forbiddenKeys = new Array("a", "s", "c", "x","u");
var key;
var isCtrl;
if (window.event) {
key = window.event.keyCode;
//IE
if (window.event.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
else {
key = e.which;
//firefox
if (e.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
if (isCtrl) {
for (i = 0; i < forbiddenKeys.length; i++) {
//case-insensitive comparation
if (forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase()) {
return false;
}
}
}
return true;
}
</script>
3. Add to lots of white spaces to before you staring your codes
it may fool someone
There isn't really anyway to do it that would stop a someone who is sophisticated.
There isn't really a way to do that. Perhaps the only thing you could do is to disable the right click feature via JavaScript, but still that wouldn't stop a user who's experienced enough to copy it. However, check this out.
for php, separate the code you don't want seen from the rest of your code with:
<?php
for($i=0;$i<1000000;$i++){
echo "\n";
}
?>
<some html="what you want to hide">
<?php
for($i=0;$i<1000000;$i++){
echo "\n";
}
?>
This will effectively kill the view source aspect (at least for a few minutes)
if it is a viewing source, he will not wait for the results.
Also, this does not seem to slow the page load
I know, it's a little late, but I guess you are looking for something called obfuscation. For Javascript files for example are many obfuscation tools available that you can use for the build process of your webpage. The code is transferred in an unreadable format. Some VPS providers are offers plugins that run during the build process and do that job for you.
As many have said, there's no real way to hide source code. There's been some good suggestions but I haven't seen this. This will encode it so nobody can read it, and it will 100% work for HTML. Only thing is anyone smarter than a light bulb will be able to decode it the same way it was encoded. You also cannot encode JavaScript or PHP; HTML only. developers.evrsoft.com offers a free encoder. But again, it can be decoded as quickly as it was encoded.
It'll look like this:
<h1>This will be encoded</h1>
Will be:
<script>
<!--
document.write(unescape("%3Ch1%3EThis%20will%20be%20encoded%3C/h1%3E"));
//-->
</script>
Again, don't encode PHP or JS.
I am using an iFrame to load a page whose url is specified in a text box. Here is my code :
<iframe id="import_url_iframe">
</iframe>
I use jQuery change event to get the change of the url in the text box :
$("#wiki_form_url").change(function(){
var value = $(this).val();
$("#import_url_iframe").attr("src", value);
});
This works fine if I click outside after specifying the url in the text box. But, I need to make this so when I write the url in the text box, it should show the page in iFrame (without any click outside). How can I accomplish that ?
Use an keydown event, possibly with a delay so that it loads after a delay (i.e. when the user hasn't typed for X seconds). So:
var timeout = null;
$("#wiki_form_url").on('keydown', function(){
timeout = setTimeout(function(){
// load URL here
}, 1000);
});
And implementing #JCOC611's suggestion as well, taking code from here, add this code as well:
$("#wiki_form_url").on('keydown', function (e){
if(e.keyCode == 13){
timeout = null;
// Load URL here
}
})'
You could take it further still, and add handlers for when the text box loses focus
$("#wiki_form_url").on('focusout', function (){
timeout = null;
// Load URL here
})'
Obviously I know how to do this with DefaultButtons within an ASP.NET web form. However, the way our client side developer wrote the code, he has a submit button done via javascript:
So the javascript is rendering the HTML.
<img id="submitBMI" onclick="quizCalc(); return false;" class="btnHover" src="Submit.gif">
Is there anyway to make this a DefaultButton?
Thanks guys.
If you mean to have the quizCalc() method be called when, for example, the enter key is pressed in a textbox of that form, then you could just set the onsubmit handler of the form to call that method:
<form ... onsubmit="quizCalc(); return false;">
If you want a little more control on which input elements call the method then you could look at using onkeypress with a single handler onKeyPress(event), check out a similar question
Update
You could do what Jonathan says, but just remove the return false as that cancels the keypress from adding characters to the textbox.
document.onkeydown = function(e)
{
var keyCode = document.all ? event.keyCode : e.which;
if(keyCode == 13) quizCalc();
}
Assuming you aren't using a js library, this will work if enter is pressed anywhere on the page:
document.onkeydown = function KeyDown(e)
{
var keyCode = document.all ? event.keyCode : e.which;
if(keyCode == 13) {
quizCalc();
return false;
}
}