469,343 Members | 5,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

open new popup windows and focus a certain one

dmjpro
2,476 2GB
Today I facing a strange problem.

Expand|Select|Wrap|Line Numbers
  1. window.open(url,'_blank');
  2.  
It opens a separate window in IE but in others where new Tab in same window allowed, is not working.
I mean it opens in different Tab but in same Window.
How can i make this in separate window?
One more thing ..............
Expand|Select|Wrap|Line Numbers
  1. window.focus();
is not working for Tab System Browsers.
Please help.

Kind regards,
Dmjpro.
Sep 11 '07 #1
18 3145
gits
5,390 Expert Mod 4TB
heya dmjpro,

you have to set the width and height:

Expand|Select|Wrap|Line Numbers
  1. window.open('www.google.com','_blank', 'width=200,height=200');
kind regards
Sep 11 '07 #2
dmjpro
2,476 2GB
heya dmjpro,

you have to set the width and height:

Expand|Select|Wrap|Line Numbers
  1. window.open('www.google.com','_blank', 'width=200,height=200');
kind regards
Hey Gits, Thanks for your reply.
It is working fine but i want to focus particular window.
As I found it works in IE fine but in others not.
Please help.

Kind regards,
Dmjpro.
Sep 11 '07 #3
gits
5,390 Expert Mod 4TB
can you give an example for the problem?

kind regards
Sep 11 '07 #4
dmjpro
2,476 2GB
can you give an example for the problem?

kind regards
Ok.
Have a look at this.

Expand|Select|Wrap|Line Numbers
  1. function test()
  2.             {
  3.             try{
  4.                 var win_array = new Array();
  5.                 for(var i=0;i<10;i++){
  6.                 win_array[i] = window.open('','_blank','height=200,width=200');
  7.                 win_array[i].document.title = 'test________'+(i+1);
  8.                 }
  9.                 var win_num = Math.round(Math.random()*10);
  10.                 win_array[win_num-1].focus();
  11.                 }catch(e){alert(e.description);}
  12.             }
  13.  
As a result it always gets focus on the last window.
Please help.

Kind regards,
Dmjpro.
Sep 11 '07 #5
don't get me wrong djmpro

Expand|Select|Wrap|Line Numbers
  1. var win_num = Math.round(Math.random()*10);
  2. win_array[win_num-1].focus();
but [win_num-1] can sometimes give value of -1
Sep 11 '07 #6
gits
5,390 Expert Mod 4TB
hmmm ...

i tried something ... have a look at the following example, may be it helps:

Expand|Select|Wrap|Line Numbers
  1. // open a window and hold a ref
  2. var t = window.open('http://www.google.de','test', 'width=200,height=200'); 
  3.  
  4. // create a callback that gets the t-ref
  5. var cb = function(t) {
  6.     t.opener.focus();
  7. };
  8.  
  9. // call the cb
  10. cb(t);
kind regards
Sep 11 '07 #7
dmjpro
2,476 2GB
don't get me wrong djmpro

Expand|Select|Wrap|Line Numbers
  1. var win_num = Math.round(Math.random()*10);
  2. win_array[win_num-1].focus();
but [win_num-1] can sometimes give value of -1
Sorry!
It will be......
Expand|Select|Wrap|Line Numbers
  1. win_array[win_num!=0?win_num-1:win_num].focus();
  2.  
Kind regards,
Dmjpro.
Sep 11 '07 #8
dmjpro
2,476 2GB
hmmm ...

i tried something ... have a look at the following example, may be it helps:

Expand|Select|Wrap|Line Numbers
  1. // open a window and hold a ref
  2. var t = window.open('http://www.google.de','test', 'width=200,height=200'); 
  3.  
  4. // create a callback that gets the t-ref
  5. var cb = function(t) {
  6.     t.opener.focus();
  7. };
  8.  
  9. // call the cb
  10. cb(t);
kind regards
Thanks for your reply!
But I want any window to be focused.
Your code only makes Opener window to be focused.
This is not my Objective.
Please Help.

Kind regards,
Dmjpro.
Sep 11 '07 #9
gits
5,390 Expert Mod 4TB
hi ...

this works analogue, with a small adaption ... simply pass the win-ref to focus to the the cb:

Expand|Select|Wrap|Line Numbers
  1. var t = window.open('http://www.google.de','test', 'width=200,height=200'); 
  2.  
  3. var t1 = window.open('http://www.google.de','test1', 'width=200,height=200'); 
  4.  
  5. var cb = function(win) { win.focus(); }; 
  6.  
  7. cb(t);
kind regards
Sep 11 '07 #10
dmjpro
2,476 2GB
hi ...

this works analogue, with a small adaption ... simply pass the win-ref to focus to the the cb:

Expand|Select|Wrap|Line Numbers
  1. var t = window.open('http://www.google.de','test', 'width=200,height=200'); 
  2.  
  3. var t1 = window.open('http://www.google.de','test1', 'width=200,height=200'); 
  4.  
  5. var cb = function(win) { win.focus(); }; 
  6.  
  7. cb(t);
kind regards
Thanks for your reply!
I tried this ..........

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script language = "JavaScript">
  4.             function test()
  5.             {
  6.             try{
  7.                 var win_array = new Array();
  8.                 for(var i=0;i<5;i++){
  9.                 win_array[i] = window.open('','_blank','height=200,width=200');
  10.                 win_array[i].document.title = 'test________'+(i+1);
  11.                 }
  12.                 var win_num = Math.round(Math.random()*5);
  13.                 //win_array[win_num-1].focus();
  14.                 getFocus(win_array[win_num!=0?win_num-1:win_num]);
  15.                 }catch(e){alert(e.description);}
  16.             }
  17.             function getFocus(win)
  18.             {
  19.                 win.focus();
  20.             }
  21.         </script>
  22.     </head>
  23.     <body onload = test()>
  24.     </body>
  25. </html>
  26.  
but found not working.
Please Help!

Kind regards,
Dmjpro.
Sep 11 '07 #11
gits
5,390 Expert Mod 4TB
hi ...

i looked over it ... the following is working. forget about the cb and so on ... ;) i like to use cbs everywhere ... but you don't need ...

Expand|Select|Wrap|Line Numbers
  1. var win_array = [];
  2. for(var i=0; i < 3; i++){
  3.     win_array[i] = window.open('http://www.google.com',
  4.                    '_blank','height=200,width=200');
  5.     win_array[i].document.title = 'test________'+(i+1);
  6. }
  7.  
  8. var win_num = Math.round(Math.random()*3);
  9. var w_ref = win_array[win_num !=0 ? win_num-1 : win_num];
  10.  
  11. w_ref.focus();
kind regards
Sep 11 '07 #12
gits
5,390 Expert Mod 4TB
i changed the thread title to better describe the content ... since it is going in two directions now ...

kind regards
Sep 11 '07 #13
dmjpro
2,476 2GB
hi ...

i looked over it ... the following is working. forget about the cb and so on ... ;) i like to use cbs everywhere ... but you don't need ...

Expand|Select|Wrap|Line Numbers
  1. var win_array = [];
  2. for(var i=0; i < 3; i++){
  3.     win_array[i] = window.open('http://www.google.com',
  4.                    '_blank','height=200,width=200');
  5.     win_array[i].document.title = 'test________'+(i+1);
  6. }
  7.  
  8. var win_num = Math.round(Math.random()*3);
  9. var w_ref = win_array[win_num !=0 ? win_num-1 : win_num];
  10.  
  11. w_ref.focus();
kind regards
Again failed.
But what I think you changed nothing.
I trying in Mozilla.
var win_array = [] this does not work in IE.
I think var win_array = new Array() works in Most Browsers.
But I still finding out the solution.
It works fine in IE but not in IE.
Please help me again.

Kind regards,
Dmjpro.
Sep 11 '07 #14
gits
5,390 Expert Mod 4TB
hi ...

i changed your last code here:

Expand|Select|Wrap|Line Numbers
  1. getFocus(win_array[win_num!=0?win_num-1:win_num]);
and my last code worked in Firefox ... definitly!

which IE? test the following in the address-bar of IE:

Expand|Select|Wrap|Line Numbers
  1. javascript:var i = [];alert(typeof i);
in case you get object - it works ... IE6 did it!

kind regards
Sep 11 '07 #15
dmjpro
2,476 2GB
hi ...

i changed your last code here:

Expand|Select|Wrap|Line Numbers
  1. getFocus(win_array[win_num!=0?win_num-1:win_num]);
and my last code worked in Firefox ... definitly!
But it does not work for me.

which IE? test the following in the address-bar of IE:

Expand|Select|Wrap|Line Numbers
  1. javascript:var i = [];alert(typeof i);
in case you get object - it works ... IE6 did it!

kind regards
Yeah!
Sorry...it works in IE.

Kind regards,
Dmjpro.
Sep 11 '07 #16
gits
5,390 Expert Mod 4TB
... test again with my working code and use:

Expand|Select|Wrap|Line Numbers
  1. var w_ref = win_array[0];
  2.  
instead of:

Expand|Select|Wrap|Line Numbers
  1. var w_ref = win_array[win_num !=0 ? win_num-1 : win_num];
  2.  
the first opened popup should be focused. is it?

kind regards
Sep 11 '07 #17
dmjpro
2,476 2GB
... test again with my working code and use:

Expand|Select|Wrap|Line Numbers
  1. var w_ref = win_array[0];
  2.  
instead of:

Expand|Select|Wrap|Line Numbers
  1. var w_ref = win_array[win_num !=0 ? win_num-1 : win_num];
  2.  
the first opened popup should be focused. is it?

kind regards
Na!
It's not working.
Please help.

Kind regards,
Dmjpro.
Sep 11 '07 #18
gits
5,390 Expert Mod 4TB
hmmm ... i don't get it ... ;( ... when started from the html-page it will not work ... when i start it from the firebug-console it does ... strange problem indeed ...
Sep 11 '07 #19

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by venkatesh | last post: by
3 posts views Thread by NeverLift | last post: by
23 posts views Thread by Markus | last post: by
13 posts views Thread by ldan | last post: by
4 posts views Thread by Csaba Gabor | last post: by
13 posts views Thread by tochiromifune | last post: by
7 posts views Thread by anthony.turcotte | last post: by
19 posts views Thread by Sonnich | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.