Here is a java script function that opens a new window (popup) and puts it on center of screen:
<script>
function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
</script>
The link example would be like this:
<a href="javascript:void(0);" onclick="PopupCenter('http://www.nigraphic.com', 'myPop1',400,400);">CLICK TO OPEN POPUP</a>
CLICK TO OPEN POPUP
This is a COPY and PASTE script, tested on internet explorer 7 / 6 and firefox 2.
Comments
i like this script but i
i like this script but i would like you to tell me what should i do to add a "previous" and "next" link button in the pop up window, so the user doesnt have to open and close windows all the time, if he likes to see more pictures.... any ideas?
bookmarklet from above code
I'd like to make a bookmarklet from this so that I can pop up a plain window to use for webcams, etc, but haven't been successful. Any help would be appreciated. Thanks!
I didn't get the point
sorry I didn't get the point.
would you please tell me more or show me an example?
Positioning Javascript
Hello, i need your help
I Have this code for a float menu, i want it to stay 1024px from Left, but on laptops, with a diferent resolution, the position of float menu changes, it is still 1024px but no longer at the distance that i want. I need some kind of distance from the center of the page, only i don't know how to do it, can you help me?
Here's my code:
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function JSFX_FloatDiv(id, sx, sy)
{
var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
var px = document.layers ? "" : "px";
window[id + "_obj"] = el;
if(d.layers)el.style=el;
el.cx = el.sx = sx;el.cy = el.sy = sy;
el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
el.floatIt=function()
{
var pX, pY;
pX = (this.sx >= 0) ? 0 : ns ? innerWidth :
document.documentElement && document.documentElement.clientWidth ?
document.documentElement.clientWidth : document.body.clientWidth;
pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ?
document.documentElement.scrollTop : document.body.scrollTop;
if(this.sy<0)
pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ?
document.documentElement.clientHeight : document.body.clientHeight;
this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
this.sP(this.cx, this.cy);
setTimeout(this.id + "_obj.floatIt()", 40);
}
return el;
}
JSFX_FloatDiv("divTopLeft", 1024,220).floatIt();
changing background color
How can you change the background color of the pop-up?
thanks in advance
kato
CSS + HTML
Hi,
The only way of changing background color is using CSS and styles.
The background color is not related to the above java script code, actually the code opens a PAGE (maybe HTML, ASP, PHP, ...).
You have to work on page file, the following lines of HTML & CSS shows a way to change the background of page.
<body style="background-color:red;">or
<body style="background-image:url(PATH-TO-IMAGE/SAMPLE.GIF;">I hope it helps you.
Post new comment