PDA

View Full Version : popup coming back to the front?


Rosey
05-24-2004, 12:32 PM
I'm using this code for the popups:


<script language=JavaScript>

<!--

function Open(url) {
var winOptsB = 'toolbar=1,location=1,dir ectories=0, left=200, top=200'
+ 'status=0,menubar=no,scro llbars=yes,'
+ 'resizable=yes,width=440, height=300'
RemoteWin = window.open(url,'Win',winOptsB)
}


//-->
</script>


and then the links look like this:

<a onclick="Open('yourlink.htm');return false;" href="popup.htm">Click</a>


Now having a lot of popups on a page, when you click on one and the popup comes up, if you go back to the page without closing the popup, the popup stays behing the browser you are clicking on. I know it has something to do with focus but I just don't know where to put it or how to put it in there :/

agent002
05-24-2004, 01:12 PM
Hi Rosey,
you're not really the one that should have control over where the user has his windows... the user is :) You could try adding this between the <head> and </head> tags of the page in the popup:
<script type="text/javascript">
window.onblur = function(){
window.focus();
}
</script>
but it's effects are rather lame; in IE, the popup won't pop back on the screen but its button in the task bar starts blinking. About Mozilla I don't know, it won't do any more I guess, in Opera it won't do anything at all.

Rosey
05-24-2004, 01:16 PM
it's not for ads or anything, it's something that they click on to get links to resources and stuff. If you had a whole bunch of links that popped with other links for your visitors but the popup kept staying behind, that would be annoying, don't you think?
I mean if i were visiting a site like that and I had to either keep closing the popup or keep click on the popup itself to make it show up, I would get frustrated.

I'll try what you said and see how it works. I thought I had tried that already but I'll just try adding that instead of combining it in.

edit:

Ok i tried it and it doesn't work in netscape so probably not in mozilla either but in IE, it makes the popup stay there all the time, that's TOO annoying. When people go back to the main page and click again on a link that opens a popup, i want it to open in the same popup that's already open and bring that popup back to the front. If no popup is open, then it would create it.

agent002
05-24-2004, 01:24 PM
I understand what you mean, I understood it already when I wrote my previous post... however, when I did that, I didn't think of a way to get around it... which seems to work (in IE). If you put this on the main page:
<script type="text/javascript">
var win = window.open('popup.html', '', 'width=400,height=350');

function focusMe(){
win.focus();
}
</script>
and this on the popup page:
<script type="text/javascript">
window.onblur = function(){
if(window.opener && !window.opener.closed){
window.opener.focusMe();
}
}
</script>
And there you have a popup that focused itself promptly when you blur the window. In IE.

Rosey
05-24-2004, 03:00 PM
That didn't work, it made a popup show up on the main page which shouldn't be there (a popup with a 404 error) and it didn't make the popups come back to the front.

:(

agent002
05-24-2004, 03:01 PM
you need to implement it to your actual popup script... can you show it to me please and I'll see if I can do that :)

Rosey
05-24-2004, 03:13 PM
sure it's at

http://healingbeam.com/temple.htm

The links on the left are the ones that popup. I put it the way it was before I became obsessed with making the popups come back to the front.

Tussi
05-25-2004, 03:28 PM
I think I know what u mean, I think I may have the same thing on my website.
I use this to open the window, which also closes the old one, if its open
:
<script language="JavaScript" type="text/JavaScript">
var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
if(popUpWin)
{
if(!popUpWin.closed) popUpWin.close();
}
popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=yes,copyhistor y=no,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
</script>

agent002
05-25-2004, 03:39 PM
Hi Rosey,
I don't know if Tussi's code is what you want or not, but here's mine anyway. Add this function below your Open() function:
function focusWin(w){
w.focus();
}
and add this code between the <head> and </head> tags of every page that you load to a popup:
<script type="text/javascript">
window.onblur = function(){
if(window.opener && !window.opener.closed){
window.opener.focusWin(this);
}
}
</script>
You could also put that in a .js file and include it on the page. I tried to avoid the code in the popup entirely by trying to set a windowobject.onload from the opener window... it worked fine in Opera and Firefox but not in IE.

Rosey
05-25-2004, 05:42 PM
agents, yours didn't work on netscape either :(


and tussi, what do you links look like? I'm really bad at javascript

agent002
05-26-2004, 07:37 AM
I know... Netscape protects its users well enough. But it worked on IE right? And you didn't mean you don't get any popup at all in Netscape?

agent002
05-26-2004, 07:40 AM
Originally posted by Rosey
and tussi, what do you links look like? I'm really bad at javascript
To me, it looks like:
popUpWindow('http://www.google.com', 120, 80, 400, 380);
Where the arguments are:
http://www.google.com - URL
120 - distance from left, in pixels
80 - distance from top, in pixels
400 - width in pixels
380 - height in pixels