This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Dreamweaver > August 2004 > javascript pop up window
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
javascript pop up window
|
|
| phlaphed 2004-08-26, 12:19 pm |
| Hello,
I am using the following script to open a pop up window when the user clicks
an image:
(in the HEAD)
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops =
'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resiz
able'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
// End -->
</script>
(in the BODY)
<a href="site.htm"
onclick="NewWindow(this.href,'window','900','600','no');return false;"><img
src="images/logo.gif" width="200" height="115" border="0"></a>
This works fine in Netscape & Safari but doesnt work in Explorer (Mac & PC).
Does anyone have any suggestions??
Thanx in advance...
| |
| Gordon 2004-08-26, 12:19 pm |
| phlaphed wrote:
> Hello,
> I am using the following script to open a pop up window when the user clicks
> an image:
use this in the head:
<script language="JavaScript" type="text/JavaScript">
var newWindow = null;
function closeWin(){
if (newWindow != null){
if(!newWindow.closed)
newWindow.close();
}
}
function popUpWin(url, type, strWidth, strHeight){
closeWin();
if (type == "fullScreen"){
strWidth = screen.availWidth - 10;
strHeight = screen.availHeight - 160;
}
var tools="";
if (type == "standard" || type == "fullScreen") tools =
"resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
if (type == "console") tools =
"resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=0,top=0";
newWindow = window.open(url, 'newWin', tools);
newWindow.focus();
}
</script>
and link using this:
<a href="path/to/your/file.htm" target="popUpWin"
onclick="popUpWin(this.href,'console',550,550);return false;">Open
Window</a>
This is a generally better method and still works if javascript is
disabled by the user.
Hope that helps
Gordon M
| |
| phlaphed 2004-08-26, 12:20 pm |
| Thanx for your reply, it works a ttreat!
One thing though, how can I get the pop-up window to open in the centre of the screen instead of opening top left?
Thanx again for your reply.
| |
| Gordon 2004-08-26, 12:20 pm |
| phlaphed wrote:
> Thanx for your reply, it works a ttreat!
>
> One thing though, how can I get the pop-up window to open in the centre of the screen instead of opening top left?
>
> Thanx again for your reply.
Hi,
Change the top=0,left=0 values for 'console' until it is positioned
where you would like it.
| |
| phlaphed 2004-08-26, 12:22 pm |
| Thanks again for your reply, how do it tell it to be centred in the available monitor space? so that no matter what size monitor the user has, the new window appears in the centre of the screen?
|
|
|
| | Copyright 2003 - 2009 forum4designers.com Software forum Computer Hardware reviews |
|