Keystroke working in IE not in Firefox - javascript

I am just trying a simple application, to make the browser fullscreen. this is working for Internet Explorer, but not for firefox.
Also I want to know, that can the same thing be done in Mac OC? do i have to make changes for Mac OS (using safari, firefox etc)
the code it below.
<html>
<head>
<script type="text/javascript">
function fullScreen()
{
var obj = new ActiveXObject("Wscript.shell");
obj.SendKeys("{F11}");
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="fullScreen()" />
</form>
<p>By pressing the button above, a function will be called. The function will alert a message.</p>
</body>
</html>
Regards
Zeeshan

All modern browsers, including IE8, allow the user to disallow a script's opening, moving or resizing a window. Also, IE allows you to prohibit activeX from untrusted (internet) sites,
and the other browsers don't have native activeX. so your solution may have very few successes, and a lot of errors and security warnings.
Of course, users can press f-11 anytime- maybe you could suggest they do so.

I believe ActiveXObject is IE specific so it will never work on FF.

Related

from chrome, i want to launch google in IE

I Want to: from chrome i want to launch google.com in IE.
Issue: when i run in chrome, google doesnt open. but if i am using IE, than google open up in IE
<Script>
function openURL(){
var shell = new ActiveXObject("WScript.Shell");
shell.run("iexplore http://google.com");
}
</Script>
<a onclick="openURL()" href=""> test </a>
The reason why this works in Internet Explorer (IE) and not Chrome is because ActiveXObject is not a web standard, and is only supported by IE. What you're asking for is unfortunately not possible at this time.
If this is just for you then you could create a custom protocol to open up internet explorer like you can do with the windows 10 calculator Calculator://
Then you would be able to launch it in plain html
Open Internet Explorer
Calculator example:
Open Calculator
https://support.shotgunsoftware.com/hc/en-us/articles/219031308-Launching-applications-using-custom-browser-protocols
You may also want to take a argument as a website to open somehow

JavaScript pop-up, can't change URL

So I've been experiencing several issues around pop-up windows within a corporate Intranet site, i.e. JavaScript 'window.open' the last one brought to my attention is the inability to change the URL of a pop-up once it's opened. I first tried this on Edge then Firefox to confirm.
After playing with the pop-up window options, I found that if I set 'toolbar=1' then I could change the URL in Firefox but not Edge or IE.
I was using the following code in a w3schools editor
<!DOCTYPE html>
<html>
<body>
<p>Click the button to open a new browser window.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
window.open('https://www.w3schools.com','123','width=560,height=340,toolbar=1');
}
</script>
</body>
</html>
This seems to be a Windows 7 and 10 issue on IE or Edge. Is there a new security setting somewhere that I'm missing?

Browser freezing after selecting file in input field

I have a form containing an input file field [<input type="file" id="select-file" accept=".md"><label for="select-file">Select import file</label>]. It has defined a jQuery handler for the change event [$("#form").on("change", "#select-file", handler)] to fire as soon as I selected a file.
It works flawlessly on Linux with Firefox at work and at home with Windows using Firefox and Chrome.
Instead at work with Windows using Chrome or Firefox, the browser freeze for about 8 sec after selecting the file. Only after this hiatus I can push other buttons on the form and the "change" event fires.
Discarding the hypothesis that Windows and work does not mesh, the freeze seems related to the different network disks available at work. Can anyone suggest what I have to check and hopefully a way to avoid the freeze? Thanks!
Small example:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>File Select</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
</head>
<body>
<div id="import-form">
<input type="file" id="select-file" accept=".md">
<label for="select-file">Select a file</label>
<p id="selected-file">No file selected</p>
</div>
<script>
$("#import-form").on("change", "#select-file", function(e) {
$("#selected-file").text(e.target.value.split('\\').pop());
});
</script>
</body>
</html>
Chrome freezes for few seconds when after any use of file field.
It was because I had a shortcut in "Quick Access" menu in windows explorer. This shortcut has been linked with a folder shared by network. I've removed this shortcut and everything is good now.

Copy to clipboard not working in safari

copy on clipboard working in all browser but not working in safari code is
head>
<title>copy test</title>
</head>
<body>
<button onclick="copier()">Copy</button>
<textarea id="myText">Copy me PLEASE!!!</textarea>
<script>
function copier(){
document.getElementById('myText').select();
document.execCommand('copy');
}
</script>
</body>
</html>
so for safari what i have to do please help me..thanks in advance.
This is for 'design mode' where the browser effectively turns the document into an editor. The execCommand API originated with IE and was later added to HTML5. Exactly which commands are supported, as well as their behavior varies across browsers. Clipboard access is considered a security risk.
please check this link

Using window.print() or alternative on Android devices

On Android devices (I have tested Nexus 5, Nexus 10, Galaxy S4 and Galaxy Tab 3), the window.print() command in JavaScript doesn't do anything. As far as I can tell it doesn't even register an error.
I know for a fact that most if not all of these browsers can print because you can use mobile Chrome's menu to choose "print".
Why doesn't window.print() trigger the behavior you would expect (opening the clients print menu)? And is there an Android alternative to window.print()?
It is clearly stated in this Documentation, "The command is supported on iOS, Chrome on Windows and Safari and Chrome on Mac. It is not supported on Android."
Android phones don't have native support for printing yet, so window.print() will not work. Which means you need to use third-party app to do the printing. You could find some alternatives in this article.
I'm working on a simular problem and came up with this solution:
$(document).ready(function($) {
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
$('button.print').click(function(e) {
e.preventDefault();
if (isAndroid) {
// https://developers.google.com/cloud-print/docs/gadget
var gadget = new cloudprint.Gadget();
gadget.setPrintDocument("url", $('title').html(), window.location.href, "utf-8");
gadget.openPrintDialog();
} else {
window.print();
}
return false;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button class="print">Print this page</button>
I haven't had the time to check if this works, i don't have an android device with me at the moment. I Would love to have some feedback on this ;-)
⚠️ [Deprecated] : Google Cloud Print will no longer be supported as of December 31, 2020. Please see the support article for help migrating.
Use Google Cloud Print (GCP) - there is no app required. The user must have set up a printer via GCP though.
This example uses GCP gadget
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Print</title>
</head>
<body>
<div>
<p>On android devices (I have tested Nexus 5, Nexus 10, Galaxy S4 and Galaxy Tab 3) the window.print() command in javascript doesn't do anything, as far as I can tell it doesn't even register an error.</p>
<p>I know for a fact that most if not all of these browsers can print because you can use mobile chromes menu to choose "print". My questions is, why doesn't window.print() trigger the behavior you would expect (opening the clients print menu).
And is there an android alternative to window.print()?</p>
</div>
<div id="gcpPrint"></div>
<script src="https://www.google.com/cloudprint/client/cpgadget.js">
</script>
<script>
var gadget = new cloudprint.Gadget();
gadget.setPrintButton(cloudprint.Gadget.createDefaultPrintButton("gcpPrint"));
gadget.setPrintDocument("text/html", "Print", document.documentElement.innerHTML);
</script>
</body>
</html>
I think, direct print() method is disabled on devices by default. I not saw so many phones or other Android devices with printer, however by USB it should be possible of course.
Instead, recommended is saving content/page as pdf and print it via some cloud print service.
At this moment, window.print() functionality works perfectly on my Android 5.0.1 device with both, Chrome and the default browser.
Now, window.print() is working on Android devices.
Download adobe acrobat in your phone and you can use windows.print() in mobile.

Categories

Resources