Open new window tab without focus on new tab [duplicate] - javascript

This question already has answers here:
I need to open a new window in the background with JavaScript, and make sure the original is still focused
(6 answers)
Closed 9 years ago.
I have such situation. I try to open a window with window.open function new window was opened in a front of main window, how can i open it in background of main window, without focus on new. Is it possible to do such thing?

What you seek is called a "pop-under" window
Open a new window using let handle = window.open()
Lose focus of the new window by using handle.blur()
The return focus to your existing window using window.focus()
Example:
var handle = window.open('https://stackoverflow.com/');
handle.blur();
window.focus();
However, it's not a guarantee as user browser settings may override this behavior, especially pop-up blockers.

No you cant open window behind the main window. if you are using window.open() then it will be top of the main window. that's how the pop up windows works.
alternatively you can do this
Window.open();
yourMainWindow.focus();

Try using the Following
window.open("http://localhost/123", '_blank');

Related

How to open a url in new window without losing the focus of current window [duplicate]

This question already has answers here:
I need to open a new window in the background with JavaScript, and make sure the original is still focused
(6 answers)
Closed 9 years ago.
How to open a url in new window without losing the focus of current window .
I want to open a new url for every 20 secs of time.
I used the following code in a page where the function is called after some time period but not working
var win=window.open(url,'_blank');
window.focus();
This may help you... but it is not recommended to open new popups every 20 second since this will be the worst user experience ever
create a new popup window using window.open()
blur newly created window using window.blur()
focus your main window using window.focus()

Open a new tab rather than a new window [duplicate]

This question already has answers here:
Open a URL in a new tab (and not a new window)
(33 answers)
Closed 9 years ago.
I want to open a new tab using jquery. The code should be pretty simple, nevertheless the following code is not working hence it opens a new window
window.open('url', '_blank');
How do I open a new tab instead of a new window?
It's not possible for you as the developer to determine.
Browsers have a setting that decides what to do when this happens, so the end user is the one who decides how the new window/tab will open.
The closest to "controlling" this, that I've seen, is when I pass a size in the third parameter of window.open, it "forces" a new window (at least it has in the past). Of course, this most likely isn't consistent across browsers. And that is the opposite of what you're looking for.
It also doesn't help when there are browsers out there without the feature of tabs.

Open new window without focus on it [duplicate]

This question already has answers here:
I need to open a new window in the background with JavaScript, and make sure the original is still focused
(6 answers)
Closed 9 years ago.
I have such situation. I try to open a window with window.open function new window was opened in a front of main window, how can i open it in background of main window, without focus on new. Is it possible to do such thing?
What you seek is called a "pop-under" window
Open a new window using let handle = window.open()
Lose focus of the new window by using handle.blur()
The return focus to your existing window using window.focus()
Example:
var handle = window.open('https://stackoverflow.com/');
handle.blur();
window.focus();
However, it's not a guarantee as user browser settings may override this behavior, especially pop-up blockers.
No you cant open window behind the main window. if you are using window.open() then it will be top of the main window. that's how the pop up windows works.
alternatively you can do this
Window.open();
yourMainWindow.focus();
Try using the Following
window.open("http://localhost/123", '_blank');

Is it possible to open a new window using location.href=""? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
open and close javascript window
Is it possible to open a new window using location.href=""? If so, how?
No, setting the location of the window can only be used to load a new page in the same window.
To open a new window you use the open method with a target _blank:
window.open('http://www.guffa.com', '_blank');
To open a new browser window, use the window.open() method. For example, the following code opens this page in a new window.
myRef = window.open(''+self.location,'mywin',
'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');
http://www.javascripter.net/faq/openinga.htm

JavaScript close tab after window.open()

I've got a page which open a new window fullscreen but it still has the other page (the one which re-directs) behind so when you close the new window you are taken back to a blank page.
Is there a way to open a new window and then close the tab which is now inactive?
Currently I have some javascript like this
window.open("http://website.co.uk");
Thanks
You can technically use window.close() on the opening tab, but browsers usually will not allow JavaScript to close windows that it has not opened. Can you redirect to some useful page that the user can use once they have closed the window?
If you can add some JavaScript code to the page being opened, I think you can use window.opener.close() to close the original window. I tested it in IE8, the browser will ask for confirm before close the original window.

Categories