Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.focus(), self.focus() not working in firefox

Hi all i am developing a chat application ... i have multiple chat windows ... i want to know which windw contain new message ... i have the following code ..

function getCount()
{
    $.ajax({
       type: "POST",
       url: baseUrl + '/Chat/count',
       data: "chat_id=" + document.ajax.chat_id.value,
       success: function(msg){
                if(msg == 'new1') {
                    self.focus();
                                            //window.focus();

                }
            }
    });
}

If an operator attending both chat....

for example the url is like http://localhost/nisanth/admin/Chat/index/chatId/15 http://localhost/nisanth/admin/Chat/index/chatId/16

http://localhost/nisanth/user/Chat/index/chatId/15 http://localhost/nisanth/user/Chat/index/chatId/16

if the user 16 enter a message i need focus

http://localhost/nisanth/admin/Chat/index/chatId/16

This code is work fine with IE but not in firefox...please give me a solution... the above code is in the same html

like image 650
Nisanth Kumar Avatar asked Mar 28 '10 14:03

Nisanth Kumar


People also ask

What is window focus ()?

focus() 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.

Which method sets focus to the current window?

Window focus() The focus() method sets focus to a window. The blur() method removes focus from a window.


2 Answers

Firefox will only obey requests to raise a window if a security option is set, and it's not set by default. Chrome won't pay attention to focus() requests at all, as far as I can tell. Safari does obey focus() request.

The specific Firefox setting is in the "Tools" -> "Options" ("Edit -> Preferences" on Linux, maybe MacOS) dialog. There's a "Content" tab, and in that there's a checkbox for enabling Javascript. Along with that is an "Advanced" button that brings up another dialog, wherein one finds a checkbox to allow (or disallow) the raising and lowering of windows by page code.

edit: Here is a test page: http://gutfullofbeer.net/focus1.html and you should be able to see that Firefox will raise a window when the page calls window.focus(). You must either have the browser set up so that new windows (created with window.open()) open up in a new separate window instead of a tab, or else you can tear off the tab of the secondary page when it opens.

like image 186
Pointy Avatar answered Nov 15 '22 13:11

Pointy


I had the same problem, i though there was a problem with my JS script, after a long search i have found a solution:

1) In a new tab, type about:config in the address bar and press button "Enter". Click the button "I accept the risk!" in order to confirm the warning

2) In the search field, type dom.disable to get dom.disable_window_flip

3) If the property dom.disable_window_flip is true, double-click it to switch the value from true to false

like image 39
Shessuky Avatar answered Nov 15 '22 12:11

Shessuky