I have two pages one.html and two.html
I am opening a new window using following code
//here popup is a global variable
popup=window.open('two.html','two');
for the first time a popup window open successfully and get the focus but if I try to open it again without closing already opened popup then two.html is not getting focus for the second time.
note: I have set popup window's name as 'two'
You can use the focus
function, as used below:
<script language="javascript" type="text/javascript">
<!--
function popitup(url) {
newwindow=window.open(url,'name','height=200,width=150');
if (window.focus) {newwindow.focus()}
if (!newwindow.closed) {newwindow.focus()}
return false;
}
// -->
</script>
focusedWindow = window.open('two.html','two').focus();
Directly append the focus() to the window.open protoype
My empiric solution that always works:
setTimeout('detail.focus()', 1);
Appending .focus()
right after open does not always work, nor calling a .focus()
without setTimeout.
I know it's ugly (wanted to get rid of it right now, after some years, with no success), and I do not know the exact reasons why and how, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With