de la fenêtre.focus() ne fonctionne pas sous Google Chrome

Demandais juste si Google Chrome est à prendre en charge window.focus() à un certain point. Quand je veux dire que le soutien, je veux dire qu'il fonctionne. L'appel à elle n'a pas d'échec, il n'a tout simplement pas faire n'importe quoi. Tous les autres navigateurs n'ont pas ce problème: FireFox, IE6-IE8 et Safari.

J'ai une classe côté client pour la gestion des fenêtres de navigateur. Quand j'ai d'abord créer une fenêtre la fenêtre est au point, mais les tentatives d'attirer l'attention sur la fenêtre ne fonctionne pas.

De ce que je peux dire, ce qui semble être une caractéristique de sécurité pour éviter les pop-ups et il ne semble pas être un WebKit problème tel qu'il fonctionne dans Safari.

Je connais une idée que quelqu'un a apporté de l'avant était de fermer la fenêtre, puis la rouvrir, mais c'est une horrible solution. Une recherche sur google montre que je ne semble pas être la seule personne frustré avec ce.

Et juste pour être sur à 100% clair, je veux dire de nouvelles fenêtres, pas de tabs (onglets ne peut pas être mis de ce que j'ai lu), et toutes les fenêtres étant ouvertes sont dans le même domaine.

Toutes les idées, les solutions à part la mauvaise, celui que je mentionne ci-dessus?

Il y a un bug connecté sur le Chrome de projet à ce sujet, check it out ici. Merci de poster que Riche.

MyCompany = { UI: {} }; //Put this here if you want to test the code. I create these namespaces elsewhere in code.
MyCompany.UI.Window = new function() {
//Private fields
var that = this;
var windowHandles = {};
//Public Members
this.windowExists = function(windowTarget) {
return windowTarget && windowHandles[windowTarget] && !windowHandles[windowTarget].closed;
}
this.open = function(url, windowTarget, windowProperties) {
//See if we have a window handle and if it's closed or not.
if (that.windowExists(windowTarget)) {
//We still have our window object so let's check if the URLs is the same as the one we're trying to load.
var currentLocation = windowHandles[windowTarget].location;
if (
(
/^http(?:s?):/.test(url) && currentLocation.href !== url
)
||
(
//This check is required because the URL might be the same, but absolute,
//e.g. /Default.aspx ... instead of http://localhost/Default.aspx ...
!/^http(?:s?):/.test(url) &&
(currentLocation.pathname + currentLocation.search + currentLocation.hash) !== url
)
) {
//Not the same URL, so load the new one.
windowHandles[windowTarget].location = url;
}
//Give focus to the window. This works in IE 6/7/8, FireFox, Safari but not Chrome.
//Well in Chrome it works the first time, but subsequent focus attempts fail,. I believe this is a security feature in Chrome to avoid annoying popups.
windowHandles[windowTarget].focus();
}
else
{
//Need to do this so that tabbed browsers (pretty much all browsers except IE6) actually open a new window
//as opposed to a tab. By specifying at least one window property, we're guaranteed to have a new window created instead
//of a tab.
windowProperties = windowProperties || 'menubar=yes,location=yes,width=700, height=400, scrollbars=yes, resizable= yes';
windowTarget = windowTarget || "_blank";
//Create a new window.
var windowHandle = windowProperties ? window.open(url, windowTarget, windowProperties) : window.open(url, windowTarget);
if (null === windowHandle) {
alert("You have a popup blocker enabled. Please allow popups for " + location.protocol + "//" + location.host);
}
else {
if ("_blank" !== windowTarget) {
//Store the window handle for reuse if a handle was specified.
windowHandles[windowTarget] = windowHandle;
windowHandles[windowTarget].focus();
}
}
}
}
}
  • Je vais avoir ce problème pour IE 8 et 9.Des idées?
InformationsquelleAutor nickytonline | 2010-05-03