---
title: "centrerad popup"
type: "forum-thread"
url: "https://www.webforum.nu/amne/javascript/41570-centrerad-popup"
topic: "JavaScript"
topic_url: "https://www.webforum.nu/amne/javascript"
author: "jboy_87"
published: "2002-04-14T13:03:58.000Z"
updated: "2002-04-15T13:23:49.000Z"
replies: 4
views: 219
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/javascript/41570-centrerad-popup"
---

# centrerad popup

## #1 — jboy_87, 2002-04-14T13:03Z

kommer det här och funka??

```
[b]
function popupChat() {
if (parseInt(navigator.appVersion) >= 3){
		if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)<5){
			var tools = new Packages.java.awt.Toolkit.getDefaultToolkit();
			screen=tools.getScreenSize();
		}
		x = screen.width;
		y = screen.height;
	}   

win=window.open("popup.html", "Suryoyo Zone jIRC","height=220,width=520" + parseInt(y/2-height/2-16) + ",left=" + parseInt(x/2-width/2-5) + ",width=" + width + ",height=" + height);
}  
[/b]
```

Permalänk: https://www.webforum.nu/p/41570

## #2 — jboy_87, 2002-04-14T13:07Z

funkar inte

Permalänk: https://www.webforum.nu/p/645787

## #3 — ThACRoW, 2002-04-14T13:44Z

detta fungerar för mig

```
function centerPopup(w,h)
{
	var x, y;
	if (top.window.document.body)
	{
		x = Math.round((top.window.screenLeft + top.window.document.body.clientWidth) / 2 - (w / 2));
		y = Math.round((top.window.screenTop + top.window.document.body.clientHeight) / 2 - (h / 2));
	}
	return 'width='+w+',height='+h+',left='+x+',top='+y;
}
```

och sen kallar du på funktionen så här:

```
window.open('...', '...',  centerPopup(302,200));
```

där 302 och 200 är bredden och höjden på fönstret

Permalänk: https://www.webforum.nu/p/645806

## #4 — jboy_87, 2002-04-14T15:34Z

kör en irc grej!!

```
function popupChat() {
if (parseInt(navigator.appVersion) >= 3){
		if (navigator.appName == "Netscape" && parseInt(navigator.appVersion)<5){
			var tools = new Packages.java.awt.Toolkit.getDefaultToolkit();
			screen=tools.getScreenSize();
		}
		x = screen.width;
		y = screen.height;
	}   

win=window.open("popup.html", "Suryoyo Zone jIRC","height=220,width=520" + parseInt(y/2-height/2-16) + ",left=" + parseInt(x/2-width/2-5) + ",width=" + width + ",height=" + height);
}     

function send()
{
   if (document.UserInfo.NICKNAME.value == null ||
                                        document.UserInfo.NICKNAME.value == "")
   {
        window.alert("Du måste skriva in nick name.")
        return false
   }

 var USERNICK = document.UserInfo.NICKNAME.value

 win=window.open("","IRC","resizable=no,height=330,width=510")
```

Permalänk: https://www.webforum.nu/p/645849

## #5 — jboy_87, 2002-04-15T13:23Z

nån som kan hjälpa

Permalänk: https://www.webforum.nu/p/646306

---

Tråden på webben: https://www.webforum.nu/amne/javascript/41570-centrerad-popup
