Link to home
Start Free TrialLog in
Avatar of pccosm
pccosm

asked on

Global variable not global

I am using this code to open a login popup. Once the login is correct, the popup window is maximized and used for a web application.  If the user gets back to the popup opener and clicks again on the popup opener link, I want to check if the popup is still open, and give focus to it instead of requesting the user to enter the user/password combination.
The following code that I managed to get from a forum does not work and I can not see why. Any help will be appreciated.

<SCRIPT LANGUAGE="JavaScript">

var newwin;

function goNewWin(iLang) {
alert(typeof(newwin));
if ((newwin) && (newwin.open) && !(newwin.closed))
      {newwin.focus();}
else
      {
            newwin=window.open('http://www.mycie.net/ssl/admin/login.asp?l='+iLang,'Win_Admin','left=400,top=200,width=600,height=50,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,fullscreen=0');
            newwin.document.bgColor="#F5ECDC";
            newwin.focus();
      }
}
...
</SCRIPT>

<body>
<script language="vbscript" runat="server">
...
call response.write("<a href=""""><img border=""0"" src=""pub/img/door_secured.gif"" width=""72"" height=""72"" onclick=""goNewWin(" & iLang & ")""></a>")
</script>

Notes:
1. I added the <a> tag just to show the link hand. Otherwise the user does not see the active area.
2. The Alert msg in goNewWin returns undefined everytime I click on the link even if the popup is open.

I just found out the problem is caused by the anchor that I mention in note 1. above. The code works if I remove it. Is there a solution with the anchor present? if not is there another way to show the hot spot on the image?

Avatar of hielo
hielo
Flag of Wallis and Futuna image

Try this (copy and paste from here):

var newwin=null;

function goNewWin(iLang) {
  alert(typeof(newwin));
  if ((newwin)  && !(newwin.closed))
  {
     newwin.focus();
  }
  else
  {
    newwin=window.open('http://www.mycie.net/ssl/admin/login.asp?l='+iLang,'newwin','left=400,top=200,width=600,height=50,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,fullscreen=0');
     newwin.document.bgColor="#F5ECDC";
     newwin.focus();
  }
}
ASKER CERTIFIED SOLUTION
Avatar of Bane83
Bane83
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pccosm
pccosm

ASKER

Thanks. That does it. Can you an explanation - or refer me to - of what href="#" means?
The # is used to indicate a position on the page to which the browser should scroll to.  You'll see this most often on pages which have a series of links at the top which correspond to sections of text below (such as a FAQ page).

You would have something like:

<a href="#definition">Click here to read a definition of xyz</a>
<a href="#suggest">Click here to suggest a new definition for xyz</a>

<h2><a name="definition">Definition:</a></h2>
Blah blah blah

<h2><a name="suggest">Suggest a new definition</a></h2>
Blah blah
<input ... etc