Have looked at the answers to previous questions and am not sure if it
is the same issue as I am having. Some of the possible answers I have found
on the net are aged so am not sure whether anything has changed regards this.
I have this code to check for a cookie and then either open one or two
tabs dependent on whether a cookie is found.
On the html side I have a link like this:
<a target='_blank' onclick="newTab()" href="http://www.test.com">
In the head section the newTab() function does the cookie check then
if needed opens a window like this:
window.open('http://www.test.com/members/','_blank');
When the link is clicked the above works fine in Firefox and IE and both
windows open when needed but in Chrome only the onclick tab opens and not
the main url regardless of the cookie.
I imagine this is an issue relating to opening tabs/windows in Chrome but
I thought that the above would be dealt with by Chrome as the opening windows
are the result of a user click.
Am I missing something simple or is it a restriction on Chrome?
Thanks for any advice.
Indeed as answered by CBroe the reason for the problems was because
I had used _blank as the window name for both.
I changed one over to _parent and it is at least working like this now
so thanks for the assistance.
Related
Just like the title says, I'm wondering whether it's possible to detect when I click on "Background Page" for my test plugin on the "chrome://extensions/" page.
Right now when I open the background page, the console is undocked. I saw this post and found ways to make it work inside each content script. But is there a way to make the plugin detect it's own console opening?
This function from that post inside my background.js doesn't seem to detect anything.
chrome.tabs.query({url:'chrome-devtools://*/*'}, function(tabs){
if (tabs.length > 0){
console.log('opened');
}
});
Any advice would be highly appreciated.
Devtools windows are not visible to tabs/windows APIs anymore.
This has changed since the answer from '14 was posted - therefore this method no longer applies.
Unfortunately, I can't find a link to the Chromium issue that implemented that.
I want to create elements which (when clicked) will guide visitors towards two differenct websites (both in new windows). How can I do this? Below are the two ways which I tried, which both do not work as only one page/ window is opened. Thanks in advance!
Timo
The solution as suggested here: How to make a link open multiple pages when clicked . But maybe the solution is outdated, but for me only the first webpage is openend (with all the indicated solutions. (for example the code which is suggested there)
HTML Click Here
$('a.yourlink').click(function(e) {
e.preventDefault();
window.open('https://www.youtube.com/watch?v=H9XIXFwpyEc');
window.open('https://stackoverflow.com/search?q=open+multiple+pages');
});
While both using a class and an id with both a different a href and both with the extra options of opening new window also does not work as it only opens the first window
HTML Click Here
$('.yourlink').html(''); // Add page
$('.yourlink a').attr('target', '_blank');// Make sure it opens in new window
$('#extra').html(''); // Add page
$('#extra a').attr('target', '_blank');// Make sure it opens in new window
Using Chrome, I'm not seeing the problem you describe. But when I tested it in IE, I suddenly got a "popup blocked" message.
It's not strange though. I'd hate it if a single click on a link could suddenly spawn 10 new windows. In this scenario I actually think IE handles it better (by blocking the second window).
The thing is that window.open will only work if the action that invokes it is a trusted event. That usually means a user-initiated event, like click. But what Chrome doesn't account for (I assume) is that a single trusted event can then invoke several window.open.
I've tried to work around this feature, but have not (yet) been able to fool IE. The options, as I see it, are:
Ask users to add your site to the popup exceptions (internet settings).
Spawn the pages in iframes within your own site
Ask users to use another browser ;)
Or the obvious:
Use separate links for the windows
This question already has answers here:
window.focus(), self.focus() not working in firefox
(3 answers)
Closed 9 years ago.
Does anyone have a clue on how to be able to use window.focus() in FireFox? (27.0.1).
I have tried all the about:config settings out there but still no luck.
My code looks something like this:
var wi = window.open('myUrl');
wi.focus();
== EDIT ==
I'm trying to make this work in FireFox on my machine, not for any other users so please
refrain from the standard "let your users decide" or "it depends on the user's settings" as
I want to get this to work for a local project :)
Tools > Options, Content area, "Advanced" button to the right of "Enable JavaScript" should give you the option to allow this behavior. If you're on Linux, the navigation might be slightly different.
Note, it is generally considered best practice to allow the user to choose what window should be in focus.
EDIT:
This is about:config you're referring to: dom.disable_window_flip
In FF 27.0.1 I am able to open a new window with focus by providing window name and option parameters to window.open, and then calling focus.
var wi = window.open('http://www.google.com', 'window_name', 'height=200,width=200');
wi.focus();
Example here: http://jsfiddle.net/CLVh2/
For Chrome support, you'll want to check out: Google Chrome "window.open" workaround?
EDIT: FOR TAB SUPPORT
If you want to open a tab and give the tab focus in FF (27.0.1), and simply calling window.open('url') is not giving you the desired result, try checking the "When I open a new tab, switch to it immediately" option. It can be found in Tools > Options > Tabs
According to Window.focus specification from Mozilla, that's not possible. It depends on the user's settings.
Makes a request to bring the window to the front. It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns.
I am opening pop up windows from a website (flash content) the following way:
RING = window.open(path,'RING_Projekt','width=800,height=600,scrollbars=no,top=' + t + ',left=' + l +'');
The HTML file opened in the popup is valid HTML with a <title>, yet Chrome (all other browsers do work fine) will display "Untitled" in the title bar.
Does anyone know why this is happening and if there is an error / workaround that could fix this? Or is this some kind of a pop up blocker malfunction / bug?
Thanks!
EDIT: Playing around, I noticed the following (unfortunately it ADDS to my confusion...): the page with the flash content opens another popup (displaying news) on load by doing:
var NEWS = window.open('popup/news.htm','RING_news','width=400,height=400,scrollbars=no,top=20, left=20');
When I now open a popup with the function mentioned in the above post, then go and close the news-Popup opened on load and then switch back to the "on-click"-Popup the popup magically acquired a name. When you close this and open it again, the name is gone again.
To be honest: I don't get it. I should be able to have more than one pop-up, right? Also, I cannot see any naming problems or anything else that could explain this behavior.
Am I missing something big here? Or is this a plain bug?
Ok, I am a 99.99% sure this is a Chrome bug, so I'll answer this myself.
Chrome seems to read the specified title correctly from the HTML (as it will be displayed in the task bar), but seems to have problems when having to display the name in the bar on the popup (see screenshot below). When you start to fiddle with the popup (move / resize), the title will sometimes appear and disappear again. Yet, the names in the task bar will always be right (that plus the fact that it works in every other browser lets me think it is a bug).
I am running Chrome 14.0.835.186 m on Windows Vista.
http://code.google.com/p/chromium/issues/detail?id=113201
its a open bug
This is a bug with Chrome. However, there is a workaround for this.
If you put the following script in the page that opens in the popup window, it seems to work fine.
<script language"text/javascript">this.window.resizeBy(1,1);this.window.resizeBy(-1,-1);</script>
The second argument to window.open isn't the <title> of the new window, used by <a target="...">, for example.. The title is determined by the content of the page.
See MDN docs for more info.
I've written a bookmarklet to look a word up in a Chinese dictionary:
javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('%E8%AF%8D%E8%AF%AD',''))};if(Qr)(function(){window.open('http://nciku.com/search/all/'+Qr);})();
This opens a new tab with search results for your selected word or a word you type in at the prompt. Is there a way to load the new tab in the background? I'd like to keep the focus on the page I'm looking at, and look at the search results later.
There is an option "When I open a link in a new tab, switch to it immediately" in Firefox, this doesn't help.
Edit: Note that this is for my use, so an answer that tells me how to change Firefox (3.0.11) settings to do this would work as well. Also I've tried the following modification, but it's still focusing the new tab.
javascript:Qr=document.getSelection();if(!Qr){void(Qr=prompt('%E8%AF%8D%E8%AF%AD',''))};if(Qr)(function(){var%20oldWin=this;window.open('http://nciku.com/search/all/'+Qr);oldWin.focus()})();
Edit 2:
Looking around to see if I can find an answer I see this guy who's got the opposite problem (new tabs don't get focus, but he wants them to have it), but with no resolution:
Possible to set tab focus in IE7 from JavaScript
There's apparently talk about a _tab target in HTML 5, but that doesn't help me much.
http:/ /forums.whatwg.org/viewtopic.php?t=185&highlight=tab+focus
(apparently as a new user I can only post one link, so I've mauled it)
This seems pretty broken browser behaviour if this is impossible.
In FireFox type about:config and change browser.tabs.loadDivertedInBackground to true.
This has worked for me with browser bookmarklets.
source: http://lifehacker.com/263940/force-links-to-open-in-the-background
No, not programmatically through JavaScript. You don't have control over the user's browser preferences, only they have control over that.
Moreover, even if you did have control over that, you shouldn't do it, because it undermines the control that your script is given to you by the browser. If the user wants a page to open in the background, they should be able to control it, not you, as the developer.
Apparently this is only possible with previously opened windows, not the root window.
Calls to window.open with the same
window name as an already existing
window, loads the URL into that window
and gives a reference to the window
back. The window isn't given focus,
its opener property isn't changed, and
a third argument to window.open is
ignored. You can use the focus method
to give the window focus manually.
var oldWin = window.open("url.html","oldName");
oldWin.focus(); // give focus
Facing the same issue, I only noticed that if you alert() something just after opening the window, Firefox would not switch to the newly opening tab.