window.open ; focus, self

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

window.open ; focus, self

Post 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
User avatar
moiseszaragoza
Forum Commoner
Posts: 87
Joined: Sun Oct 03, 2004 4:04 pm
Location: Ft lauderdale
Contact:

Post 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
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

Post 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.
Post Reply