Page 1 of 1

window.open ; focus, self

Posted: Wed Feb 07, 2007 9:28 am
by moiseszaragoza
I am trying to open a new window when someone comes the my site

Code: Select all

<head>
<script>
function onLoad() {   
  // if (!window.survey.is not oppend allready) {
      window.open("survey.asp", 'survey');
      window.focus('self')// not working	  
   //}   
   return true;
}
</script>		  
</head>
<body onLoad="onLoad()">
but i have to check if that window is oppend before i oppen it.
and is there any way to keep the focus on the curent page

thanks

Posted: Wed Feb 07, 2007 9:58 am
by moiseszaragoza
Ok I have my popup oppening on the background


this was acomplish by

Parent Script

Code: Select all

<head>
<script>
function onLoad() { 
     survey=window.open("survey.asp");	 
   return true;
}

</script>		  
</head>
<body onLoad="onLoad()">
Newwindow

Code: Select all

<head>
<script>
function onLoad() {          
	  window.opener.focus();   
   return true;
}
</script>		  
</head>
<body onLoad="onLoad()">
now all i need is to find out if this window is open or not

Posted: Wed Feb 07, 2007 10:48 pm
by jyhm
I think that you would always want to specify a name for your window and refer to that window by its name on each event that is associated with that window. Like below I have named this window 'mywindow'.

Code: Select all

window.open('http://www.example.com/example.htm','mywindow','width=400,height=200')"> 
And perhaps use conditionals in your function:

Code: Select all

function onLoad() {   
   if (!window.survey) {
      window.open("survey.asp", 'survey');
   } else  {
      window.focus('survey');          
   }   
   return true;
} 
I hope this helps but be sure to mess around with this as I am by no means an expert with clientside scripting.