javascript - Stop download the site when password is false - javascript

I'm writing a simple Code Verify
So can I forcing the site to stop downloaded when the code is false with javascript?
My example:
<html>
<head>
</head>
<body>
<div class='content'></div>
</body>
</html>

You could do window.stop(); for most browsers besides Internet Explorer. For IE, I had to use document.execCommand('Stop');

Related

window.close not closing window in HTA application

In my HTA application I'm using a JavaScript calendar window, it opens using window.open() and closed using window.close(), when the user clicks on one of the dates. This calendar works fine on multiple browsers and versions over more than 10 years. It even works in HTA applications most of the time.
However on specific workstations running IE11. The window.close() command is simply ignored, resulting in the window left open. On other IE11 workstations it works fine. I figured that turning off the "Enable Protected Mode" checkbox on IE11, Internet Options, Security tab resolves the problem on one of the problematic workstation. However, other workstations works fine with this setting turned on and turning off this setting is not an acceptable solution.
Code sample which reproduces the problem:
HTA application
<HTML>
<HEAD>
<HTA:APPLICATION ID="OpenCloseExample" BORDER="thick" BORDERSTYLE="complex"/>
<TITLE>Open Close HTA container</TITLE>
</HEAD>
<iframe width="1024px" height="768px" src="http://localhost:28080/openclose.html"/>
</HTML>
openclose.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Main Page</title>
<script src="openclose.js"></script>
</head>
<body>
open
</body>
</html>
openclose.js
var win;
function openWindow() {
win = window.open("", "_blank", 'width=250,height=250,status=no,resizable=no,location=no,top=100,left=100');
win.document.writeln("<html><head><script src='openclose.js'></script></head><a href='#' onclick='javascript:window.opener.closeWindow()'>close</a></html>");
}
function closeWindow() {
win.window.close();
}
I can't see this working in any IE with any settings. The problem is this string: <script src='openclose.js'></script>. That is, a literal ending script tag in a string works as an ending script tag on a page, when HTML parser will find it. This means, that your script was never loaded.
To fix this, you've to break the literal tag, for example like so:
<script src='openclose.js'><\/script>
Since you have pointed out that IE11 is causing the JS not to work, you can force IE to render in an older version very easily.
<meta http-equiv="X-UA-Compatible" content="IE=9">
This meta tag is very popular amongst HTA applications for utilizing JS/ActiveX methods/properties within specific IE versions (most of them being deprecated).
For more information, visit the X-UA-Compatible Tag Wiki
Hope this helps
I figured this out eventually.
Changing:
open
to:
open
Has resolved the problem

javascript in mobile web browsers

I have this very simple html file.
<!doctype html>
<html>
<head>
</head>
<body>
<script>alert("hi");</script>
</body>
</html>
This usually runs fine in Firefox and Google Chrome on my laptop. But when I run this in Safari in an iPhone device and Google Chrome on an Android device, the JavaScript code doesn't run. That is, no alert appears. This is extremely unusual for me. Do we need to change JavaScript code when running on mobile devices? What should I do?
(function(){
window.alert('hi')
})()
<html>
<head>
</head>
<body>
</body>
<script src="aJSfile.js"></script>
</html>
Add window to alert so that it says window.alert('hi') also see the core window functions supported by most browsers
https://developer.mozilla.org/en-US/docs/Web/API/Window/alert

SWF downloads twice in IE

I see SWFs download twice in IE, but not in Chrome. I'm using IE 11. I can see the download requests in the F12 dev tools Network tab and in server access logs. Below is a simple example that exhibits the problem. I'm using swfobject 2.2. I've tried calling swfobject.switchOffAutoHideShow() before calling swfobject.embedSWF(), but that doesn't help.
You can test this by putting the HTML and swfobject.js in the same directory and browsing from the disk, so you don't need an HTTP server to test/reproduce this.
Does anyone know why this happens and how to stop the second download?
<!DOCTYPE html>
<html>
<head>
<title>My Version</title>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("http://www.adobe.com/swf/software/flash/about/flashAbout_info_small.swf",
"flashInfo", "100%", "100%", "9.0.0");
</script>
</head>
<body>
<div id="flashInfo">
<p>No flash here. Move along.</p>
</div>
</body>
</html>

How to get a javascript alert?

I'm definitely not a newbie to scripting, but this just boggles my mind. I want to invoke a function on a button click, so I first wanted to grab the buttonclick event and test that with a simple window.alert. So I just wrote the html document below.
<!doctype html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#sendButton").click(function(){
alert("clicked!!");
});
});
</script>
</head>
<body>
<form id="send-message-area">
<input type="button" id="sendButton" value="Send Message">
</form>
</body>
Unfortunately, nothing happens. At all. Since this is fairly simple code, I have no clue why this wouldn't work.
Your script tag to pull in jQuery is using the (Common|General) Internet Syntax Scheme. This tells the browser to use whatever scheme was used to load the page in loading the script. It is helpful for sites which respond to both http and https.
If you are viewing your file locally using the file:// scheme, then you should see an error that $ is not defined. This is because the script does not live at:
file://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
Please use this src in the script tag when loading locally:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
Path to src should be complete if you have hosted it somewhere.You have not added correct path to jquery library. Everything will work accordingly once you do that.
<script src="http://code.jquery.com/jquery-latest.js"></script>
Demo
According to your url starting with // the browser tries to load that file from your local file system if you're locally testing your site using an url like file://. In that case you're not loading jQuery, so the $ is undefined and your code never executed.
Use the script tag like that for local tests:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
If you run your site on a web server, the cdn-style starting with // will work again.
Code looks fine
I think you are testing in IE < 9 (jQuery 2.x not supporting IE 8)
Please change the browser or load jQuery version like 1.9 and test it
You have to update query script src to 'http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js'
I recommend to download the jQuery script then add it to your project locally instead of the remote one
use <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"> and practise to insert html tag
HTML:
<!doctype html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#sendButton").click(function(){
alert("clicked!!");
});
});
</script>
</head>
<body>
<form id="send-message-area">
<input type="button" id="sendButton" value="Send Message">
</form>
</body>
</html>
You are missing to include http:/ in your script src.
Either change your script tag like this:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
or download the Jquery file and refer locally.
Change your path to
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
and try to use jquery 1.10 for less than ie9 browser
<!--[if lt IE 9]><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><![endif]-->
<!--[if IE 9]><!--><script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script><!--<![endif]-->

Browser Compatiabilty issue for Html file with internet explorer

We have use the following html code snippet. While right click on that html file and open with the Operamini, Mozila,Safari, Chrome are working fine but it did not working in the internet Explorer.
Code snippet[html]:
<!DOCTYPE html>
<head>
<title>Simple Example</title>
</head>
<body>
<script type="text/javascript">
function displaymessage() {
alert("hai");
}
displaymessage();
</script>
</body>
Can you please any one look into this and provide suggestion to resolve the problem . Thanks in advance.
Regards,
Rajasekar
try this:
1) add html tag to open the page
2) internet explorer blocks "activeX" contents, you should click on the top and unlock them...
By default Internet Explorer restrict running script and ActiveX Controls. If you are not getting any warning, then Go to Tools --> Internet Option ---> Advanced ---> Security ---> Restore Defaults for "Security level for this zone".
Hope this may help.

Categories

Resources