00:00
00:00

Our goal is for Newgrounds to be ad free for everyone! Become a Supporter today and help make this dream a reality!

Java: Javascript Popup Tutorial

1,979 Views | 5 Replies
New Topic Respond to this Topic

Java: Javascript Popup Tutorial 2006-06-08 07:51:15


Java: Main

First, create a normal html page. You can call it anything you'd like. I'll call mine bob.
****Note you need to replace all "]" with ">"****

Put this code in bob.html:

[html]
[head]
[title]A popup window d00d[/title]
[SCRIPT TYPE='text/javascript']
<!--
function pop(width,height){
if(window.innerWidth){
LeftPosition =(window.innerWidth-width)/2;
TopPosition =((window.innerHeight-height)/4)-50;
}
else{
LeftPosition =(parseInt(window.screen.width)- width)/2;
TopPosition=((parseInt(window.screen.heigh
t)-height)/2)-50;
}
attr = 'resizable=no,scrollbars=yes,width=' + width + ',height=' +
height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
TopPosition + '';
popWin=open('', 'new_window', attr);
popWin.document.write('[head][title]Test Popup[/title][/head]');
popWin.document.write('[body][div align=center]');
popWin.document.write('[b]This is a test popup window[/b][br][br]');
popWin.document.write('Content goes here[br]');
popWin.document.write('Content goes here[br]');
popWin.document.write('Content goes here[br]');
popWin.document.write('[/div][/body][/html
]');
}
//-->
[/SCRIPT]
[/head]
[body]
[a href="javascript:pop(400,200);"]Test Popup[/a]
[/body]
[/html]

------------------------------------------
------------------\\\\

Explained:

[html]
[head]
[title]A popup window d00d[/title]
[SCRIPT TYPE='text/javascript']
<!--
function pop(width,height){
This tells the name (pop) and you can replace "pop" with anything but be sure to add it below! width and height just telling it the order of the numbers so it doesn't get confused
if(window.innerWidth){
LeftPosition =(window.innerWidth-width)/2;
TopPosition =((window.innerHeight-height)/4)-50;
}
else{
LeftPosition =(parseInt(window.screen.width)- width)/2;
TopPosition=((parseInt(window.screen.heigh
t)-height)/2)-50;
}
Normal math functions for each individual screen
attr = 'resizable=no,scrollbars=yes,width=' + width + ',height=' +
this just says that it's not resizable, that it has both scroll bars and that width ="width" number and height="height" number. You can replace "scrollbars=yes with scrollbars=1 or scrollbars=0

height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
TopPosition + '';

popWin=open('', 'new_window', attr);
This is to create a new window

Now here's the serious part of the equation:

For each line of code inside the popup window (ya know, to make it look like a webpage) you must add the popWin.document.write(' [b]content here<[b] ');
Example below:
popWin.document.write('[head][title]Popup[
/title][/head]');
popWin.document.write('[body][div align=cente]');
popWin.document.write('[b]Popup windows look like this![/b][br][br]');
popWin.document.write('Content goes here[br]');
popWin.document.write('Content goes here[br]');
popWin.document.write('Content goes here[br]');
popWin.document.write('[/div][/body][/html
]');

}
//-->
[/SCRIPT]
[/head]
[body]
[a href="javascript:pop(400,200);"]Test Popup[/a]
Thist just links the popup tutorial. the 400 number is the width (from up top) and the 200 number is the height (from up top). Don't forget to add the replacement for "pop" right next to the ":" or it won't work
[/body]
[/html]

Sorry for all the brackets but NG doesn't seem to like this. For a full code with out brackets go here
Hope you got some use out of this tutorial. Now you know how to do the thing NG does with it's flash movies/games.

Enjoy :)


Hello, from the past!

[ PHP: Main ]

BBS Signature

Response to Java: Javascript Popup Tutorial 2006-06-08 07:56:15


lol this is your 666th post 2 days after the 06/06/06

Response to Java: Javascript Popup Tutorial 2006-06-08 09:00:26


momo, having a javascript tuturial under a Java main makes no sense.


beep

BBS Signature

Response to Java: Javascript Popup Tutorial 2006-06-08 09:02:41


At 6/8/06 09:00 AM, unit_243b wrote: momo, having a javascript tuturial under a Java main makes no sense.

*sigh* how many times are you going to say this?


Hello, from the past!

[ PHP: Main ]

BBS Signature

Response to Java: Javascript Popup Tutorial 2006-06-08 09:05:34


At 6/8/06 09:02 AM, Momo_the_Monkey wrote:
At 6/8/06 09:00 AM, unit_243b wrote: momo, having a javascript tuturial under a Java main makes no sense.
*sigh* how many times are you going to say this?

twice : ) I'm just trying to help you.


beep

BBS Signature

Response to Java: Javascript Popup Tutorial 2006-06-08 09:14:17


At 6/8/06 09:05 AM, unit_243b wrote:
At 6/8/06 09:02 AM, Momo_the_Monkey wrote:
At 6/8/06 09:00 AM, unit_243b wrote: momo, having a javascript tuturial under a Java main makes no sense.
*sigh* how many times are you going to say this?
twice : ) I'm just trying to help you.

l to the olagez


Hello, from the past!

[ PHP: Main ]

BBS Signature