Solved

Check if named window exisits

Posted on 2003-12-02
10
1,822 Views
Last Modified: 2011-09-20
Is it possible to check if a window by a certain name is already open?

example:

I have windows named x, y and z

say the window that opened these windows wanted to open a window named y it would check to see if it's already open. If it is then it wouldnt try to open it again
0
Comment
Question by:chrisnetonline
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 10

Expert Comment

by:NetGroove
ID: 9862932
Yes, that is posible.

Open again a blank window with taht name and look for some attributes.
If that attributes are not there, then open the correct window.

Like this:
  wx = window.open('','winXname');
  if(wx.titel!=wx.title){
     wx.close();
     wx = window.open('wx.htm', 'winXname', 'height=100,width=100');
  }

  // use wx now.

0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9862939
Sorry,

  if(wx.title == ""){...


0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9862948
Oh, and the window naming can be from at least three sources:
1.) Second parameter of window.open()
2.) Frame name
3.) Window name attribute assignment. Like this:
<script>
window.name = 'winXname';
</script>

0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Expert Comment

by:Chiller
ID: 9862964
what u could do is:

create a var for each window, i.e. winX, winY, winZ, set them to 0 by default.
then when you open a window, u set the window handle to the var.
in the opening function u simply check is its non 0 if so open then window if not dont :).

will post some code.

[code]
var winX=0, winY=0, winZ=0;

function openWin (which)
{
      if (which=="x")
            if (winX==0)
                  winX= window.open("location.html", "winX", "...");
            else
                  alert("Window already open !\n");
            
      if (which=="y")
            if (winY==0)
                  winY= window.open("location.html", "winY", "...");
            else
                  alert("Window already open !\n");


      if (which=="z")
            if (winZ==0)
                  winZ= window.open("location.html", "winZ", "...");
            else
                  alert("Window already open !\n");
}
[/code]
0
 

Author Comment

by:chrisnetonline
ID: 9863023
NetGroove,

Here's my function:

[code]
      function OpenIMWindow(bid,bname,action)
            {
            var wx = window.open("","im_"+bname,"width=50,height=50");
            if(wx.title=="")
                  {
                  wx.close();
                  var op_wid = "400";  
                  var op_heigh = "325";                
                  LeftPosition=(screen.width)?(screen.width-op_wid)/2:100;TopPosition=(screen.height)?(screen.height-op_heigh)/2:100;
                  var option = "top="+TopPosition+",left="+LeftPosition+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0, resizable=1,width="+op_wid+",height="+op_heigh;
                  var win = window.open("ims.php?id="+bid+"&bname="+bname, "im_"+bname, option);  
                  if (action == 0){win.focus();}
                  else if (action == 1){win.blur();}
                  }
            else
                  {
                  alert("Already Open!");
                  }
            }
[/code]

I never get the already open alert box :/
0
 

Author Comment

by:chrisnetonline
ID: 9863030
i'm trying to prevent the entire window from refreshing if window.opener detects a new message first
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 9864665
NG: What is wx.title ???
0
 
LVL 10

Accepted Solution

by:
NetGroove earned 0 total points
ID: 9865252
It was a typo.
Anyway was the window.title wrong recomandation.

Check please this:

<html>
<head>
<script>
function OpenIMWindow(bid,bname,action) {
  var wx = window.open("","im_"+bname,"width=100,height=100");
  if(wx.location.href=="about:blank") {
    wx.close();
    var op_wid = "400";  
    var op_heigh = "325";                
    LeftPosition=(screen.width)?(screen.width-op_wid)/2:100;TopPosition=(screen.height)?(screen.height-op_heigh)/2:100;
    var option = "top="+TopPosition+",left="+LeftPosition+",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,

resizable=1,width="+op_wid+",height="+op_heigh;
    var win = window.open("ims.php?id="+bid+"&bname="+bname, "im_"+bname, option);  
  } else {
    alert("Already Open!");
    win = wx;
  }
  if (action == 0){
      win.focus();
  } else if (action == 1){
            win.blur();
          }
}
</script>
</head>
<body>
<a href="#" onClick="OpenIMWindow(100,'BidOne',0);return false">BidOne</a>
</body>
</html>



0
 

Author Comment

by:chrisnetonline
ID: 9869944
NetGroove... I get a message that says permission denied errors :/
0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9870147
All pages has to be in the same internet Domain.

You are not allowed to read attributes of foreign domain pages.

Tell us the url structure you are using.
And be aware that numeric (ip) and symbolic urls for same host are different domains.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question