Forum Moderators: open

Message Too Old, No Replies

New window in JScript

         

Civichunter

12:07 am on Sep 13, 2005 (gmt 0)

10+ Year Member



Hi guys,

With JScript and new windows, is there a way to sort of
well.. "combine" the two files (the main pages and popup page) into the one html file only? In another words, is there any way to incorporate all the code into one page instead of an external page which is called by the funtion ie. 'popup.html'

Cheers,

Code for Main Window:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html40/loose.dtd">
<html>
<head>

<script>
//'popup.html itself must be created first otherwise te script will not be able to locate it and generate an error
var theURL = 'popup.html';
var width = 450;
var height = 350;

function popWindow() {
newWindow = window.open(theURL,'newWindow','toolbar=no, menubar=no,resizable=yes, top=50, left=50, scrollbars=no,status=yes,location=no,width='+width+',height='+height);
}
</script>

<script>
//3000 milli-seconds = 3 seconds
setTimeout("popWindow()", 3000);
</script>

</head>
<body onload="window_Onload()">
A new window should pop up in 3 seconds

<script>
var time=new Array(0,0,0)

function window_Onload()
{
setInterval("updateTime()",1000);
}

function updateTime()
{
time[0]++
if (time[0] >= 61)
{
time[1]++
time[0]=0
}
if (time[1] >= 61)
{
time[2]++
time[1]=0
}

window.status=time[2] + " hours, " + time[1] + " minutes, and " + time[0] + " seconds."
}
</script>
</body>
</html>


=======================================
Code for Pop up window:

<html>
<body>
<form onSubmit="display()" name = "counter">
<p>
<input type="text" size="35" name="d2"></input>
</p>
<input type="SUBMIT" value = "Reset Timer"></input>
</form>

<script>
<!--
//Timer set at 60 minutes
var seconds=0
var minutes=60
document.counter.d2.value='60'

function display(){

if (seconds<=0){
seconds=60
minutes-=1
}
if (minutes<=-1){
seconds=0
minutes+=1
}
else
seconds-=1
document.counter.d2.value=minutes+" "+ "minutes " + seconds + " seconds remaining"
setTimeout("display()",1000)
}
display()

-->
</script>
</body>
</html>

dlefree

2:51 am on Sep 13, 2005 (gmt 0)

10+ Year Member



JavaScript to do all that:


var newWindow = window.open(theURL,'newWindow','toolbar=no, menubar=no,resizable=yes, top=50, left=50, scrollbars=no,status=yes,location=no,width='+width+',height='+height);

newWindow.document.write('<b>your html here</b> - might want to escape it first, though...');

By assigning the new window to a variable, you are able to assign it the write() method reliably.