Reputation: 21
i'm want to open a file in background with javascript. The code works fine in chrome but in firefox (12) and Opera new windows open in foreground.
Anybody knows what i'm doind wrong?.
Here its code of two files:
father.html:
<html>
<body>
<script>
var son=null;
function openIt(){
son=window.open('son.html','sonpage');
son.blur();
self.focus();
window.focus();
//alert("voy");
return false;
}
</script>
<a href="javascript:void(0)" onClick="openIt(); return false;">Open</a>
<a href="javascript:void(0)" onClick="son.close()">Close</a>
<button type="button" id="play2-video" onclick="son.play()">
play2 video
</button>
<button type="button" id="pause2-video" onclick="son.pausa()">
pause video
</button>
Father Page
</body>
son.html:
<html>
<Head>
<script>
function play(){
alert("Play!");
}
function stop(){
alert("Stop!");
}
</script>
</Head>
<Body>
<h1> Son Page</h1>
</Body>
Thank you!
Upvotes: 2
Views: 1855
Reputation: 14943
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" 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.
read https://stackoverflow.com/a/2533335/643500
Tried to mess with the code -- no joy
The function only needs :
function openIt(){
son=window.open('son.html','sonpage');
window.focus();
return false;
}
Try to redirect back from the opened page to the main one and see if it can be accomplished that way?
Also, look into JQuery, it might handle that with events like http://api.jquery.com/focusout/
Upvotes: 1