/    Sign up×
Community /Pin to ProfileBookmark

Modal window does not work in Firefox?

Guys:
I want to implement a modal pop up window in my application, that means focus should be always in pop up window unless user fill the information and click close.

I want to develope a cross-browser javascript library (I do not want to use the window.openModalDialog, it is IE only).

Here is the code I put in pop up window.

[CODE]var child_window_force_selector = {
init : function() {
var opener = window.opener;
var child_window = self;
if (opener.addEventListener) {
opener.addEventListener(“focus”, function() {
opener.blur();
child_window.focus();
}, false)
} else if (opener.attachEvent) {
opener.attachEvent(“onfocus”, function() {
opener.blur();
child_window.focus();
})
}
}
}
child_window_force_selector.init();
[/CODE]

It works fine in IE but does not work in firefox. I registered some onfocus hanlder on the child window for debug purpose, it seems even child_window.focus() got invoked, but event handler is not triggered at all, I searched it seems not a known issue for firefox….

can anyone give me a hint on this.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterNov 27.2006 — Just off the top of my head, try a timeout for Firefox:
<i>
</i>setTimeout(function(){child_window.focus()},1);
Copy linkTweet thisAlerts:
@zeeho_81authorNov 27.2006 — It is because of the setting in FF2.0

advanced javascript - Raise and lower window.

http://www.google.com.au/search?hl=en&q=raise+and+lower+window&btnG=Google+Search&meta=
Copy linkTweet thisAlerts:
@pint_of_bestNov 27.2006 — I had to make a pop-up window modal recently. I found a simple way to do it was to add the following to the page. Hope this helps.

[CODE]<body onblur="self.focus();">[/CODE]
Copy linkTweet thisAlerts:
@zeeho_81authorNov 28.2006 — pint_of_best : the defect of ur solution is you can never type things in pop up window.. I think it is the best solution for a non-input pop up window

All : After apply the setting it works perfectly with the following code.
[CODE]var window_force_focus = {
init : function() {
var opener = window.opener;
var child_window = self;
if (opener.addEventListener) {
opener.addEventListener("focus", function() {
setTimeout(function(){
if (!opener || !child_window) return;
if (!opener.blur || !child_window.focus) return;
opener.blur();
child_window.focus();
}, 0);
}, false)
} else if (opener.attachEvent) {
opener.attachEvent("onfocus", function() {
opener.blur();
child_window.focus();
})
}
}
}
window_force_focus.init();[/CODE]



But in firefox, I got some error message like this when I close the popup window and focus on the parent window.

[Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIDOMJSWindow.setTimeout]" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: http://localhost:8080/workbench/javascript/lib/window_force_focus.js :: anonymous :: line 22" data: no]

What is that mean ? Can anyone help me???
Copy linkTweet thisAlerts:
@felgallNov 28.2006 — Just remember that focus and blur are not required to be supported by window objects and so many browsers don't support them for windows. More support focus for windows than support blur but since the command requires both it will onloy work in browsers that support both non-standard events.

eg. Opera supports focus on windows but not blur.

To quote from the standards.

The onfocus event occurs when an element receives focus either by the pointing device or by tabbing navigation. This attribute may be used with the following elements: A, AREA, LABEL, INPUT, SELECT, TEXTAREA, and BUTTON.[/quote]
Copy linkTweet thisAlerts:
@zeeho_81authorNov 28.2006 — fixed, now it works perfectly in both IE and Firefox
Copy linkTweet thisAlerts:
@SiroshkaDec 07.2006 — fixed, now it works perfectly in both IE and Firefox[/QUOTE] How your problem were resolved?

Does it works in FF 2.0?
Copy linkTweet thisAlerts:
@zeeho_81authorDec 08.2006 — var window_force_focus = {

init : function() {

var opener = window.opener;

var child_window = self;

if (opener.addEventListener) {

if (!opener || !child_window) return;

if (!opener.blur || !child_window.focus) return;

opener.addEventListener("focus", function() {

setTimeout(function(){

opener.blur();

child_window.focus();

}, 0);

}, false)

} else if (opener.attachEvent) {

opener.attachEvent("onfocus", function() {

opener.blur();

child_window.focus();

})

}

}

}

window_force_focus.init();[/QUOTE]

I think it will work, But I have not try. The only thing you need to do is include it in ur child window
×

Success!

Help @zeeho_81 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...