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
Solved

Check if named window exisits

Posted on 2003-12-02
10
1,820 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
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Writing comments on <p></P> or paragraph 2 19
Html Table looping 4 25
Access RV042 GUI / Browser Issues 25 48
formvalidation.io validate form on class click 4 16
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

828 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