Solved

bring popups to front and refresh

Posted on 2004-04-03
8
1,201 Views
Last Modified: 2008-03-17
when a user requests a pop-up via link, is their a way to make sure the pop-up appears on top of the page
 instead of behind it if the previous popupof the same name lost focus?

The user requested links open up precisely sized images, sole swf's or external websites in the center
of the page.  If they skip manually closing the first popup and request another popup on the parent page,
the old popup loses focus and loads the a new pop-up behind the parent page, hiding it from the user.

Not only that but the next popup that opens has the same dimmensions as the last pop-up, even though
the new popup's size is defined otherwise (hence my desire for the popup to refresh)

Because the pop-up's aren’t always HTML, I'm hoping that the code to bring the pop-up to the front is
contained in the parent HTML page.

(I could just load a new pop-up each time, but that would obviously clutter things up and peeve the user.)


here's what I have:

<html><head>
<script language="javascript" type="text/javascript">
<!--
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}
// -->
</script></head>

<body><br><br>

First link load's without a problem<br>
<a href="http://experts-exchange.com/images/indexLogo.gif" onclick="NewWindow(this.href,'same-popup','350','25','no','center');return false" onfocus="this.blur()">link to picture</a>
<br><br>
...but if you click on the next link without closing the previous one manually
(with the close 'X' in the upper right corner of the browser), the popup loses focus
and loads the next popup behind the parent page<br>
<a href="http://oddtodd.com/laidoff2.swf" onclick="NewWindow(this.href,'same-popup','300','200','no','center');return false" onfocus="this.blur()">Link to flash</a>
<br><br>
Not only that but the next popup that opens has the same dimmensions as the last
pop-up, even though the new popup's size is defined otherwise<br>
<a href="http://google.com" onclick="NewWindow(this.href,'same-popup','500','400','no','center');return false" onfocus="this.blur()">Link to web page</a>
<br><br><br>
Currently, each page must be closed manually so that the next one will load correctly

</body></html>
0
Comment
Question by:Marketing_Insists
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 250 total points
ID: 10748872
Right after teh open just add:

win.focus();
And that will bring it to the front.

Cd&
0
 

Author Comment

by:Marketing_Insists
ID: 10748993
would that be in the manner of
 onfocus="this.blur();win.focus()
?
0
 

Author Comment

by:Marketing_Insists
ID: 10749006
Ooops, just noticed that the pevious code won't work in IE

tis again;
<html>
<head>
<script language="javascript" type="text/javascript">
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}
</script>
</head>
<body><br><br>
<a href="http://experts-exchange.com/images/indexLogo.gif" onclick="NewWindow(this.href,'same','350','25','no','center');return false" onfocus="this.blur()">Link-to-picture</a>
<br><br>
<a href="http://oddtodd.com/laidoff2.swf" onclick="NewWindow(this.href,'same','300','200','no','center');return false" onfocus="this.blur()">Link-to-flash</a>
<br><br>
<a href="http://google.com" onclick="NewWindow(this.href,'same','500','400','no','center');return false" onfocus="this.blur()">link-to-html</a>

</body></html>
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10749114
Right here where you open:

win=window.open(mypage,myname,settings);}

Just change it to:

win=window.open(mypage,myname,settings);win.focus();}

And it will bring it to the top in order to bring focus to it.

Cd&
0
 
LVL 25

Assisted Solution

by:devic
devic earned 250 total points
ID: 10749167
and the first line in your function can be:
if(win)win.close();
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 10749273
Glad we could help. Thanks for the A. :^)

Cd&
0
 

Author Comment

by:Marketing_Insists
ID: 10749293
Thanks!

Both of you had part of the answer,

You guys in cahoots?  ;-)
0
 
LVL 25

Expert Comment

by:devic
ID: 10749347
;)

btw, i noticed, if i open the window with location ".sfw", i can not close this window at once.
here another version:
================
<html>
<head>
<script language="javascript" type="text/javascript">
var win=null;
function NewWindow(mypage,myname,w,h,myscroll,pos)
{
if(win)win.close();
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
var settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',myscrollbars='+myscroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open("about:blank",myname,settings);
win.document.write("<html><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><body>")
var ext=mypage.substr(mypage.lastIndexOf('.')+1)
if(ext.match(/gif|jpg|png/))win.document.write("<img src="+mypage+">");
else if(ext=="swf")win.document.write("<embed src="+mypage+" width=100% height=100% type=application/x-shockwave-flash></embed>");
else win.document.write("<iframe src="+mypage+" width=100% height=100% width=100% height=100% frameborder=0></iframe>");
win.document.write("</body></html>")
win.focus();
}
</script>
</head>
<body><br><br>
<a href="http://experts-exchange.com/images/indexLogo.gif" onclick="NewWindow(this.href,'same','350','25','no','center');return false">Link-to-picture</a>
<br><br>
<a href="http://oddtodd.com/laidoff2.swf" onclick="NewWindow(this.href,'same','300','200','no','center');return false">Link-to-flash</a>
<br><br>
<a href="http://google.com" onclick="NewWindow(this.href,'same','500','400','no','center');return false">link-to-html</a>
</body></html>
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I post more than 1 item to php backend 24 60
Table header must be on top 2 57
Google Chrome: Debugging AJAX call 6 38
Sticking text to shapes in Raphael.js 6 41
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'…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

734 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