Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to restrict opening multiple windows by using window name

    Hi all,

    I am new to this forums.I have requirement .In my Application I have so many links (urls) are there.If I am clicking on on link one new window is opening.for that i am using window.open(url,"windowname","');.If I am click the some link i am checking for the link is allready opend are not .if allready opend then i am setting the focus to the same window .this is working fine.
    But instead of giving window name in window.open method we are mainting window name through the application .My problem is when I am clicking the another link(url) if it contains the same window name then it should give an alert and it should not give access to open a new window.please helpout to resolve this problem.



    Thanks in advance

    Sree

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You can play with this:

    Code:
    var winPop = null;
    function openWindow(){
      if(winPop && !winPop.closed){
        alert("Pop Up is Open");
      }
      else{
        winPop = window.open(.......);
      }
    }
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,333
    Thanks
    11
    Thanked 587 Times in 568 Posts
    you can avoid a global variable like this : (im bored)


    Code:
    function openWin(url){
        openWin.pu= openWin.pu ||  window.open("");
       openWin.pu.location.href= url;
      return openWin.pu;
    }
    the popup's window object would then be located at openWin.pu, as well as any variable set by calling openWin.

    eg:
    popupwin = openWin("blah");
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #4
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Thanks for your replay.I am able to open windows and restricting ..

    BUt my requirement is Two different urls with having same windowname then if I opend one window with windowname xyz and url like "http://localhost/one.html After that I am opening another window
    with windowname xyz and url like "http://localhost/two.html
    then it should give alert like a window is allredy opend eith this window name..
    I hope you got my point and waiting for your replay

    Thanks

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,333
    Thanks
    11
    Thanked 587 Times in 568 Posts
    i see.
    Code:
    function openWin(url){
      openWin.pu= openWin.pu ||  window.open(url);
    if( openWin.url && (url !== openWin.url) ){ return alert("Page in Use!"); }
      openWin.pu.focus();
      openWin.url = url;
      return openWin.pu;
    }
    Last edited by rnd me; 09-29-2008 at 07:17 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •