PDA

View Full Version : Closing window automatically?



esawyja
03-08-2007, 02:26 PM
Hi,
I open a avi that plays in a new window, how can I get the window to close when the avi is done playing?
thanks for the help!!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Movie Titles</title>
<style type="text/css">

.basictab ul{
margin: 4px;
padding: 3px 0;
margin-left: 0;
font: bold 12px Verdana;
border-bottom: 1px solid gray;
list-style-type: none;
text-align: left; /*set to left, center, or right to align the menu as desired*/
}

.basictab li{
display: inline;
margin: 0;
}

.basictab li a{
text-decoration: none;
padding: 3px 7px;
margin-right: 3px;
border: 1px solid gray;
border-bottom: none;
background-color: #f6ffd5;
color: #2d2b2b;
}

.basictab li a:visited{
color: #2d2b2b;
}

.basictab li a:hover, .basictab li a.current{
background-color: #DBFF6C;
color: black;
}

.basictab li a:active{
color: black;
}

#tabcontentcontainer{
width:95%; /*width of 2nd level content*/
height:1.5em; /*height of 2nd level content. Set to largest's content height to avoid jittering.*/
}

.tabcontent{
display:none;
}

</style>


<script type="text/javascript">

/***********************************************
* DD Tab Menu script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display (or "" if no corresponding tab content)]:
var initialtab=[1, "sc1"]

//Turn menu into single level image tabs (completely hides 2nd level)?
var turntosingle=0 //0 for no (default), 1 for yes

//Disable hyperlinks in 1st level tab images?
var disabletablinks=0 //0 for no (default), 1 for yes


////////Stop editting////////////////

var previoustab=""

if (turntosingle==1)
document.write('<style type="text/css">\n#tabcontentcontainer{display: none;}\n</style>')

function expandcontent(cid, aobject){
if (disabletablinks==1)
aobject.onclick=new Function("return false")
if (document.getElementById && turntosingle==0){
highlighttab(aobject)
if (previoustab!="")
document.getElementById(previoustab).style.display="none"
if (cid!=""){
document.getElementById(cid).style.display="block"
previoustab=cid
}
}
}

function highlighttab(aobject){
if (typeof tabobjlinks=="undefined")
collectddtabs()
for (i=0; i<tabobjlinks.length; i++)
tabobjlinks[i].className=""
aobject.className="current"
}

function collectddtabs(){
var tabobj=document.getElementById("ddtabs")
tabobjlinks=tabobj.getElementsByTagName("A")
}

function do_onload(){
collectddtabs()
expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

</script>
</head>

<body bgcolor="#FFFFCC" text="#660099" link="#FF3399" vlink="#669966" alink="#CC3333">

<div id="ddtabs" class="basictab">
<ul>
<li><a href="c:\test\nickytest.html" onMouseover="expandcontent('sc1', this)">Back to MAIN menu</a></li>
</ul>
<div>

<DIV id="tabcontentcontainer">


<div id="sc1" class="tabcontent">
<u><div align="center"><center><b><strong><u><font face="times new roman, times, serif"><font color="#003333"></font></font></strong></u></b></center></div></u>
</div>

</DIV>
</body>
</html>

<body bgcolor="#FFFFCC">
<table border="2" cellspacing="5" cellpadding="5" width="100%" bgcolor="#ffffcc" bordercolorlight="#330000" bordercolordark="">

</body>
</html>
<tr>
<td><a href="c:\test\Sahara.avi" onclick="var win=window.open('','mywindow','height=600, width=1000');win.document.write('\x3Chtml\x3E\x3Chead\x3E\x3Ctitle\x3EBlockBusters\x3C/title\x3E\x3Cstyle\x3Ehtml,body {margin:0;padding:0;}\x3C/style\x3E\x3C/head\x3E\x3Cbody\x3E\x3Cembed src=\'c:/test/Sahara.avi\' width=\'1000\' height=\'600\' autostart=\'1\' showcontrols=\'0\' type=\'application/x-mplayer2\' pluginspage=\'http://www.microsoft.com/windows/windowsmedia/download/\'\x3E \x3C/embed\x3E\x3C/body\x3E\x3C/html\x3E');return false;">Sahara</a><br></td>
</tr>

Veronica
03-08-2007, 03:13 PM
You could add code to close the window after a set period of time, ie the length of the movie, plus a bit of padding to make sure it doesn't close before the movie is done.

setTimeout('self.close();',30000);

The number is in milliseconds, so 30000 equals 30 seconds

Blake
03-08-2007, 03:48 PM
I would use start the timer with the onload event so that it takes the loading time in to account.

esawyja
03-09-2007, 10:44 AM
Hi thanks, but where would I put the statement setTimeout('self.close();',3000)?

Blake
03-09-2007, 02:03 PM
<td><a href="c:\test\Sahara.avi" onclick="var win=window.open('','mywindow','height=600, width=1000');win.document.write('\x3Chtml\x3E\x3Chead\x3E\x3Ctitle\x3EBlockBusters\x3C/title\x3E\x3Cstyle\x3Ehtml,body {margin:0;padding:0;}\x3C/style\x3E\x3C/head\x3E\x3Cbody\x3E\x3Cembed onload=\"setTimeout(\'self.close();\',3000)\" src=\'c:/test/Sahara.avi\' width=\'1000\' height=\'600\' autostart=\'1\' showcontrols=\'0\' type=\'application/x-mplayer2\' pluginspage=\'http://www.microsoft.com/windows/windowsmedia/download/\'\x3E \x3C/embed\x3E\x3C/body\x3E\x3C/html\x3E');return false;">Sahara</a><br></td>


By the way, that code is absolutely unreadable. It would be a good idea to put the onclick event in a function:



<script type = "text/javascript">

function openWindow()
{
var win=window.open('','mywindow','height=600,width=1000');
win.document.write('<html><head><title>BlockBusters</title></head><body>');
win.document.write('<embed src="c:/test/Sahara.avi" width="1000" onload="setTimeout(\'self.close();\', 3000);"');
win.document.write('width="1000" height="600" autostart="1" showcontrols="0" type="application/x-mplayer2"');
win.document.write('pluginspage="http://www.microsoft.com/windows/windowsmedia/download/"></embed>');
win.document.write('</body></html>');
return false;
}

</script>

<a href="test\Sahara.avi" onclick="return openWindow();">Sahara</a>

esawyja
03-22-2007, 11:19 PM
Hi Blake, I finally got aroung testing this, but it does not close the window in which the avi file is played in, could it be IE, I'm using version 6, also this
<td><a href="c:\test\Sahara.avi" onclick="var win=window.open('','mywindow','height=600, width=1000');win.document.write('\x3Chtml\x3E\x3Chead\x3E\x3Ctitle\x3EBlockBusters\x3C/title\x3E\x3Cstyle\x3Ehtml,body {margin:0;padding:0;}\x3C/style\x3E\x3C/head\x3E\x3Cbody\x3E\x3Cembed onload=\"setTimeout(\'self.close();\',3000)\" src=\'c:/test/Sahara.avi\' width=\'1000\' height=\'600\' autostart=\'1\' showcontrols=\'0\' type=\'application/x-mplayer2\' pluginspage=\'http://www.microsoft.com/windows/windowsmedia/download/\'\x3E \x3C/embed\x3E\x3C/body\x3E\x3C/html\x3E');return false;">Sahara</a><br></td>
Plays the avi in the current window, IE does not open a new one
Any ideas please?
Thanks

thetestingsite
03-28-2007, 01:27 AM
If I'm not mistaken, this part:



\x3Cembed onload=\"setTimeout(\'self.close();\',3000)\"


should be this:



onload=\"setTimeout(\'self.close();\',3000)\"


because there is no "embed" attribute in the body tag.
Hope this helps.