javascript in mobile web browsers - javascript

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

Related

Chrome issue - Open mobile SMS app by clicking URL

I need to open the sms application of mobile with prefilled body and recipient by clicking on a URL.
so I wrote this code and it is working fine in firefox.
But it is not working in chrome.
<html>
<head>
<script type="text/javascript">
function f(){
window.location="sms://+12345?body=1234";}
</script>
</head>
<body onload="f();">
</body>
</html>
Any idea to fix?

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 - Stop download the site when password is false

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');

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>

Facebook like-box code does not display scrollbar in android as well as iphone device

I want to display facebook like-box in my app, on all the desktop browsers it's working right. When I open page on android and iphone device html scrollbar does not appear there. I am not getting what is the problem with web-kit browsers.
My code is below:
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>facebook </title>
</head>
<body>
<div id="fb-root"></div><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like-box href="http://www.facebook.com/imoment" width="292" show_faces="true" stream="true" header="false"></fb:like-box> </body>
</html>
Try using the HTML5 version of the fb:like instead. That might make it more compliant with web-kit.

Categories

Resources