PDA

View Full Version : Popup window generator



DanV
02-27-2009, 05:01 PM
1) Script Title: Popup window generator

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex8/popwin.htm (http://www.dynamicdrive.com/dynamicindex8/popwin.htm)

3) Describe problem:

Nice script but I'm wondering if there is any way to keep the window in place for the other links in the list. As it stands, when I click on another link the window is minimized out of view on the bar and then I have to maximize it to see the second link result.

Since this is one of those "build-it" scripts I have included the one I generated for my purposes The first is the head section:




<script language="javascript" type="text/javascript">
<!--
/****************************************************
Author: Eric King
Url: http://redrival.com/eak/index.shtml
This script is free to use as long as this info is left in
Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
****************************************************/
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,re sizable=yes';
win=window.open(mypage,myname,settings);}
// -->
</script>



And the following is the link code for wherever placed:




<a href="http://www.google.com" onclick="NewWindow(this.href,'mywin','500','370','yes','center');return false" onfocus="this.blur()">YourLinkText</a> <p>



Thanks.

DanV

jscheuer1
02-28-2009, 04:05 PM
There are various approaches. If you give each link's onclick event a different name, it will make a new window, not use the one that's minimized:


<a href="http://www.google.com" onclick="NewWindow(this.href,'mywin','500','370','yes','center');return false" onfocus="this.blur()">YourLinkText</a>

But this can (if a user clicks on a bunch of these links) leave you with a bunch of minimized windows. That can be a good thing, but if the user clicks on the same link again, they will still have to restore its window to see it. So you can put code on the pages in the new windows:


<script type="text/javascript">
if(self.opener)
window.onblur = function(){self.close();};
</script>

That way they cannot be minimized, they will close instead and be ready to be opened anew if clicked for again, thereby once again gaining the foreground.

Now, it is best to use both of these approaches together, just in case a browser decides to close a named window while opening it, which would make for no window. And it requires that you have access to the pages in the new windows. But for many implementations, this is just fine.

However, opening a new window isn't always the best idea. It can be blocked, or forced into a tab (a user's browser settings and/or their way of activating the link can control this). Also, you have less control over the 'chrome' of the window than you might like. For all of these reasons, it is often better to use a DHTML type window like:

http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm

There are many other scripts with various looks and feels that do this sort of thing.

DanV
02-28-2009, 04:55 PM
Thank you for the reply.

Please correct me if I didn't understand your explanation but you said, "... it will make a new window, not use the one that's minimized". What I'm wondering is if there's a way to keep the window fixed, i.e., if I click on the second, third and so forth links the window doesn't minimize or close. All that one would see is the same fixed window calling up a new url just like a browser; 'a browser within a browser'. Of course, the user has the option of minimizing and closing it if they like but by deault the window would stay in place, only the url changes.

I guess it's like what you see in some sites where the frame is in place and then a list of links in the sidebar that change the frame's content. Thing is, I like the window's look and versatility more than a static frame. So in essence, I'm looking for a window that acts like a frame but more flexible than a frame such as the DHTML one you mentioned.

I hope the above made sense.

Thanks

jscheuer1
02-28-2009, 06:10 PM
It did, and it sounds like you want the DHTML window or some similar script. What kind of content are you showing? Are you showing full pages, or would images and a little text be good enough?

Anyways, there is really no way to do it like you say with a real window, not exactly. You can focus the new window though (addition highlighted):


<script language="javascript" type="text/javascript">
<!--
/****************************************************
Author: Eric King
Url: http://redrival.com/eak/index.shtml
This script is free to use as long as this info is left in
Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
****************************************************/
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,re sizable=yes';
win=window.open(mypage,myname,settings);}
win.focus();
// -->
</script>

It will briefly disappear from view when you click on the page, but come right back. It is still heir to all the ills of new windows that I already mentioned. And if the window is blocked, now there will also be an error (when focus is attempted).