Chrome bug workaround: Javascript to steal focus - javascript

When I start Chrome, the new window appears as unfocused & behind the other windows. So I decided to create a workaround; I'll change my homepage url with a file from my disk which one contains javascript to steal focus and then redirect to real homepage.
What is the best method to steal focus, using javascript?
UPDATE: Here is what I attempted...
<html>
<head></head>
<body></body>
</html>
<script type="text/javascript">
myWindow=window.open("http://google.com", "_blank",
"resizable=yes, scrollbars=yes, titlebar=yes" );
myWindow.focus();
self.close();
</script>
However new window looks like popup window, Chrome doesn't display toolbars & adress bar is not editable :(
More info about the bug:
http://productforums.google.com/forum/#!topic/chrome/zyLC4Ip96pU
As far as I'm aware, this has only started on the latest update. If Chrome is already open, when I open a new window of Chrome from a shortcut in the quick launch area of my Windows toolbar, the new window does not take focus, the focus remains on the previous Chrome window. If the focus was not on the previous Chrome window when I launch the shortcut it works fine

I just published a small Chrome Extension which aims at solving this bug! So far it worked great for me (on Window 7 64-bit).
You can find it here: https://chrome.google.com/webstore/detail/chrome-new-window-focus/opmhcfhkhiodgapmnaolhmekmfihmecp
Let me know if you encounter any issues!
Cheers,
Yuvi

http://www.w3schools.com/jsref/met_win_focus.asp

Related

Open about:blank window in firefox

When i open a new window using window.open javascript, chrome opens with about:blank, but firefox opens with jsfiddle back url and if you right click on the page, you can still see the page loading. You will not see the refresh icon, instead a stop icon is appearing.
I need to open the new window with about:blank.
Here is the jsFIDDLE
Tested with Chrome 45.0
Tested with Firefox 41.1
<button id="helper">Click here for help</button>
What you are experiencing is a new Firefox behavior that passed in version 40 or 41 (sorry I did not find the reference).
Expect it to become part of google's behavior soon too, you can see people requesting it already(Chrome issue)
Unfortunately there is not much that can be done for now as it is brand new people have not found workaround or even if it is a good idea to fight against the browser... My suggestion is to not use about:blank at all and use a blank html page from your domain, that would make things easier on the users.
Instead of about:blank take #:
$("#helper").click(function(){
windowURL = window.open("#","Looking ....
EDIT
in order to prevent the browser from showing an "infinite loading", close the document:
...
openedDocument.open();
openedDocument.write(myHTML)
openedDocument.close()

How to temporally hide the Navigation Bar from Firefox extension?

I'm developing an extension for Firefox for Android and I need to programatically open a new tab with no navigation bar. I know I can do it with JS with window.open("http://www.google.com", "mywindow", "location=0,toolbar=0"); but this time I need to disable it another way, because the tab is being opened via loadURI. So, the thing is, how can I change the toolbar visibility once loadURI was executed?
Thanks in advance!
You have to make browser go to full screen mode to achieve that.
For mobile FF you have to create manifest and at there:
"fullscreen": "true"
https://developer.mozilla.org/en-US/Apps/Build/Manifest#fullscreen
I tryed a lot of things I fount over Internet but no success because there is no XUL in FF for Android. So I just solved it by calling fullscreen mode:
window.BrowserApp.selectedBrowser.contentWindow.fullScreen = true;
Where window is the chrome window, not the object window

Google chrome freezes when printing a page using window print method

I have latest google chrome version -32.0.1700.107 m installed on windows 8 machine.
I am doing this:
popup = window.open();
popup.print();
This opens a new popup and a print window appears. Now, when I go back to the page from where I triggered this, it freezes and I cannot do anything there.
Here is the small fiddle for your reference. FIDDLE
Click the button and come back to the fiddle page (do not close the print page) and try typing anything in the fiddle, it will be hanged and as soon as you will close the print page, the fiddle window will get normal.
This is in Google chrome ONLY, other browsers are working smoothly. Please help.
I tried:
Opening the popup in new window using window.open("","","width=800,height=600").
Putting popup.close().
opening it on some different OS (windows 7, XP)
But got no success
Please some kind soul help me with this issue or some work around.
This is an issue in Google Chrome and will be fixed in Chrome 36 according to this issue.

Close windows that were not opened by script using javascript [duplicate]

This question already has answers here:
window.close and self.close do not close the window in Chrome
(17 answers)
Closed 6 years ago.
I want my web application to run in a window which has no menubar, addressbar etc. I have a Default.html page and in this page I click a "Run Application" button which first opens my application in another window using window.open and then closes the current window by opening "AutoClose.html" using window.open with _self parameter
Default.html
<html>
<head>
<script type="text/javascript">
function runApp() {
// Open my application
window.open('Application.html', null, 'status:no;dialogHide:true;help:no;scroll:yes;center=yes;');
// Close this window
window.open('AutoClose.html', '_self');
}
</script>
</head>
<body>
<input type="button" value="Run Application" onclick="runApp();" />
</body>
</html>
AutoClose.html
<html>
<head>
<script type="text/javascript">
window.close();
</script>
</head>
<body></body>
</html>
My application should support IE, Firefox and Chrome and my code works fine on IE and Chrome but it is unable to close the first window on Firefox because of "Scripts may not close windows that were not opened by script" warning. On Firefox it opens the AutoClose.html but window.close() call in this page just causes the "Scripts may not close windows that were not opened by script" warning and window is not closed. By the way my application window is opened without any issues (no problem about that).
It seems that using window.open() with _self parameter trick does not work for Firefox. Since my goal is to run the application in a window without menubar, addressbar etc.
Is there any way for hiding addressbar, menubar without using window.open() (at least for Firefox)? Then I will not need to run window.close()
Is there any setting to suppress "Scripts may not close windows that were not opened by script" warning on Firefox? An "Allow scripts to close windows that were not opened by script" setting would be great (:
Is there any way to make window.close() work for "windows that were not opened by script using javascript" on Firefox?
Or, is there any other suggestions (:
Thanks in advance.
UPDATE: This is a banking application and I am just a developer not the decision maker. In other words some kind of analyst wants the application work in this way. And I am not questioning it. So "the whole thing you are trying to do is completely wrong" answers will not be really helpful.
You can't close the current window in firefox because you didn't open it. It doesn't matter that you loaded AutoClose.html into it.
But this whole business with windows is pointless. Most people have their browser set to open new windows in a new tab, and you can't prevent the menubar etc in a tab window.
I, personally, would be very irritated if you closed my window just because I used your application.
It could be the only window the user has open - in which case you just closed their browser. It could be they want to press back, and closing the tab will annoy them.
This error from firefox is correct, and if it works in Chrome that's a serious bug and you should report it.
Simply,
open(location, '_self').close();
The basic problem is that what your requirements-setter wants you to do is explicitly blocked by Firefox:
There is no way to hide the UI in a user's existing browser window, because it's user-hostile and a favorite tool of phishers.
There is no way to close the user's existing window from script, losing all the user's session history in the process.
Basically, the user has other things in the browser than just your bank thing. So assuming otherwise is more or less doomed to failure.
Is there any way you can push back on the unreasonable requirements?
This worked for me.
I used it to close the window when clicking a button in jQuery UI Dialog.
open(location, '_self').close();

resizeTo() not working in Firefox

Running Firefox 12.0. I'm just starting to write a app that I want to run on localhost. I want it to open it in a (600,400) window, but since I have Firefox set to open everything in tabs I thought I could bookmark it and right-click to open it in a new window.
$(document).ready(function() {
window.resizeTo(600,400);
});
Doesn't work. Is what I am trying to do possible?
Thanks, Jim
This isn't possible, unless the window was opened through javascript using window.open and has only 1 tab in it.
Since Firefox 7, it's no longer possible for a web site to change the default size of a window in a browser, according to the following rules:
- You can't resize a window or tab that wasn’t created by window.open.
- You can't resize a window or tab when it’s in a window with more than one tab.
MDN docs

Categories

Resources