open new popup windows and focus a certain one

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    open new popup windows and focus a certain one

    Today I facing a strange problem.

    [code=javascript]
    window.open(url ,'_blank');
    [/code]

    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 ..............
    [code=javascript]window.focus();[/code] is not working for Tab System Browsers.
    Please help.

    Kind regards,
    Dmjpro.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    heya dmjpro,

    you have to set the width and height:

    [CODE=javascript]window.open('ww w.google.com',' _blank', 'width=200,heig ht=200');[/CODE]
    kind regards

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by gits
      heya dmjpro,

      you have to set the width and height:

      [CODE=javascript]window.open('ww w.google.com',' _blank', 'width=200,heig ht=200');[/CODE]
      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.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        can you give an example for the problem?

        kind regards

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by gits
          can you give an example for the problem?

          kind regards
          Ok.
          Have a look at this.

          [code=javascript]
          function test()
          {
          try{
          var win_array = new Array();
          for(var i=0;i<10;i++){
          win_array[i] = window.open('', '_blank','heigh t=200,width=200 ');
          win_array[i].document.title = 'test________'+ (i+1);
          }
          var win_num = Math.round(Math .random()*10);
          win_array[win_num-1].focus();
          }catch(e){alert (e.description) ;}
          }
          [/code]

          As a result it always gets focus on the last window.
          Please help.

          Kind regards,
          Dmjpro.

          Comment

          • rohitchawla
            New Member
            • Jul 2007
            • 85

            #6
            don't get me wrong djmpro

            [CODE=javascript]var win_num = Math.round(Math .random()*10);
            win_array[win_num-1].focus();[/CODE]

            but [win_num-1] can sometimes give value of -1

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5388

              #7
              hmmm ...

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

              [CODE=javascript]// open a window and hold a ref
              var t = window.open('ht tp://www.google.de', 'test', 'width=200,heig ht=200');

              // create a callback that gets the t-ref
              var cb = function(t) {
              t.opener.focus( );
              };

              // call the cb
              cb(t);[/CODE]
              kind regards

              Comment

              • dmjpro
                Top Contributor
                • Jan 2007
                • 2476

                #8
                Originally posted by rohitchawla
                don't get me wrong djmpro

                [CODE=javascript]var win_num = Math.round(Math .random()*10);
                win_array[win_num-1].focus();[/CODE]

                but [win_num-1] can sometimes give value of -1
                Sorry!
                It will be......
                [code=javascript]
                win_array[win_num!=0?win_ num-1:win_num].focus();
                [/code]

                Kind regards,
                Dmjpro.

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Originally posted by gits
                  hmmm ...

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

                  [CODE=javascript]// open a window and hold a ref
                  var t = window.open('ht tp://www.google.de', 'test', 'width=200,heig ht=200');

                  // create a callback that gets the t-ref
                  var cb = function(t) {
                  t.opener.focus( );
                  };

                  // call the cb
                  cb(t);[/CODE]
                  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.

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5388

                    #10
                    hi ...

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

                    [CODE=javascript]var t = window.open('ht tp://www.google.de', 'test', 'width=200,heig ht=200');

                    var t1 = window.open('ht tp://www.google.de', 'test1', 'width=200,heig ht=200');

                    var cb = function(win) { win.focus(); };

                    cb(t);[/CODE]
                    kind regards

                    Comment

                    • dmjpro
                      Top Contributor
                      • Jan 2007
                      • 2476

                      #11
                      Originally posted by gits
                      hi ...

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

                      [CODE=javascript]var t = window.open('ht tp://www.google.de', 'test', 'width=200,heig ht=200');

                      var t1 = window.open('ht tp://www.google.de', 'test1', 'width=200,heig ht=200');

                      var cb = function(win) { win.focus(); };

                      cb(t);[/CODE]
                      kind regards
                      Thanks for your reply!
                      I tried this ..........

                      [code=html]
                      <html>
                      <head>
                      <script language = "JavaScript ">
                      function test()
                      {
                      try{
                      var win_array = new Array();
                      for(var i=0;i<5;i++){
                      win_array[i] = window.open('', '_blank','heigh t=200,width=200 ');
                      win_array[i].document.title = 'test________'+ (i+1);
                      }
                      var win_num = Math.round(Math .random()*5);
                      //win_array[win_num-1].focus();
                      getFocus(win_ar ray[win_num!=0?win_ num-1:win_num]);
                      }catch(e){alert (e.description) ;}
                      }
                      function getFocus(win)
                      {
                      win.focus();
                      }
                      </script>
                      </head>
                      <body onload = test()>
                      </body>
                      </html>
                      [/code]

                      but found not working.
                      Please Help!

                      Kind regards,
                      Dmjpro.

                      Comment

                      • gits
                        Recognized Expert Moderator Expert
                        • May 2007
                        • 5388

                        #12
                        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 ...

                        [CODE=javascript]var win_array = [];
                        for(var i=0; i < 3; i++){
                        win_array[i] = window.open('ht tp://www.google.com' ,
                        '_blank','heigh t=200,width=200 ');
                        win_array[i].document.title = 'test________'+ (i+1);
                        }

                        var win_num = Math.round(Math .random()*3);
                        var w_ref = win_array[win_num !=0 ? win_num-1 : win_num];

                        w_ref.focus();[/CODE]
                        kind regards

                        Comment

                        • gits
                          Recognized Expert Moderator Expert
                          • May 2007
                          • 5388

                          #13
                          i changed the thread title to better describe the content ... since it is going in two directions now ...

                          kind regards

                          Comment

                          • dmjpro
                            Top Contributor
                            • Jan 2007
                            • 2476

                            #14
                            Originally posted by gits
                            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 ...

                            [CODE=javascript]var win_array = [];
                            for(var i=0; i < 3; i++){
                            win_array[i] = window.open('ht tp://www.google.com' ,
                            '_blank','heigh t=200,width=200 ');
                            win_array[i].document.title = 'test________'+ (i+1);
                            }

                            var win_num = Math.round(Math .random()*3);
                            var w_ref = win_array[win_num !=0 ? win_num-1 : win_num];

                            w_ref.focus();[/CODE]
                            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.

                            Comment

                            • gits
                              Recognized Expert Moderator Expert
                              • May 2007
                              • 5388

                              #15
                              hi ...

                              i changed your last code here:

                              [CODE=javascript]getFocus(win_ar ray[win_num!=0?win_ num-1:win_num]);[/CODE]
                              and my last code worked in Firefox ... definitly!

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

                              Code:
                              javascript:var i = [];alert(typeof i);
                              in case you get object - it works ... IE6 did it!

                              kind regards

                              Comment

                              Working...