/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DHTML ScreenSaver Author : Darren Neimke
Source : http://www.showusyourcode.com/
Email : [email protected]
Date : 28-Aug-2002
Version 1.0.1
Comments:
There's still quite a few *magic* numbers in
here as I'm struggling to come to terms with
measuring the Screen innerWidth and innerHeight
values in IE.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */var is_ie5_5up = ( true )// -------------------------------------------------------------------// -------------------------------------------
// Global variables
// -------------------------------------------var gIntrvlSSRepaint ; // the timer for repainting
var gIntrvlSSListen ; // keep checking to see if time has elapsed and required to start the SS
var gIntrvlSSElapsed ; // since last activity
var counter = 0 ; // MAGIC?var gWidth, gHeight ; // store the screen dimensionsvar LINE_WIDTH = 90 ;
var ACTIVITY_TIMEOUT = 15000 ; // 15 seconds
var CHECK_ACTIVITY_INTERVAL = 1000 ; // 1 second
var REPAINT_INTERVAL = 100 ;
var SCROLLBAR_WIDTH = 0
var TASKBAR_HEIGHT = 0// If you already do stuff in a onload event handler, then you must
// call gfnSSInitialize() from there, otherwise just leave this code
// as-is and it will call itself
var gobjScreenSaver ;function screenSaverInit()
{
if (is_ie5_5up)
{
new ScreenSaver() ;
gobjScreenSaver.Init() ;
CalcScreenAvail()
gIntrvlSSElapsed = new Date().valueOf() ;
gIntrvlSSListen = setInterval( "activityChecker()", CHECK_ACTIVITY_INTERVAL ) ;
}
}// If you need to do stuff in these handlers as well, just add
// you own stuff in, but be sure to still call the ScreenSaver helpers.
window.onload = function() { screenSaverInit(); } // Instantiate the ScreenSaver
document.onkeypress = function() { activityMonitor(); }
document.onmousemove = function() { activityMonitor(); }
document.onmousedown = function() { activityMonitor(); }
document.onmouseup = function() { activityMonitor(); }
window.onresize = function() { CalcScreenAvail(); }// -------------------------------------------
// Helper functions etc.
// -------------------------------------------// used from several sections
function CalcScreenAvail()
{
gWidth = document.body.clientWidth;
gHeight = document.body.clientHeight;
if(!(typeof(gobjScreenSaver) == 'undefined'))
{
try
{
gobjScreenSaver.SetScreenSize()
}
catch(e){
// possibly route to an exception handler
}
}
}// Event Listener - called on a keypress and mousemove
function activityMonitor()
{
if(!(typeof(gobjScreenSaver) == 'undefined'))
{
try
{
gIntrvlSSElapsed = new Date().valueOf()
if(gobjScreenSaver.IsActive && !(gobjScreenSaver.IsPreview))
gobjScreenSaver.Stop() ;
}
catch(e){
// possibly route to an exception handler
}
}
}// called on a timer to invoke (Start) the screensaver
function activityChecker()
{
var tmp = new Date().valueOf()
if(((tmp - gIntrvlSSElapsed) > ACTIVITY_TIMEOUT) && !(gobjScreenSaver.IsActive))
{
gobjScreenSaver.Start()
}
}// -------------------------------------------------------------------document.writeln('<style>');
document.writeln('#myLine')
document.writeln('{')
document.writeln('position: absolute ;')
document.writeln('top: 100px ;')
document.writeln('left: 200px ;')
document.writeln('width: 100px ;')
document.writeln('height: 2px ;')
document.writeln('line-height: 2px ;')
document.writeln('overflow: hidden ;')
document.writeln('z-index: 3099 ;')
document.writeln('}')
document.writeln('#myScreensaver')
document.writeln('{')
document.writeln('position: absolute ;')
document.writeln('top: 0px ;')
document.writeln('left: 0px ;')
document.writeln('z-index: 90 ;')
document.writeln('}')
document.writeln('<\/style>')
document.writeln('<DIV Id="myScreensaver"></DIV>') ;// -------------------------------------------
// Line and Screensaver Classes
// -------------------------------------------function Line(obj, xpos, ypos)
{
this.Started = 0
this.Element = obj
this.xpos = xpos
this.ypos = ypos
this.decreaseX = true
this.decreaseY = true
this.Reset = function()
{
this.Started = 0
this.xpos = 200
this.ypos = 100
this.Element.style.display = 'none'
this.decreaseX = true
this.decreaseY = true
}
}
DHTML ScreenSaver Author : Darren Neimke
Source : http://www.showusyourcode.com/
Email : [email protected]
Date : 28-Aug-2002
Version 1.0.1
Comments:
There's still quite a few *magic* numbers in
here as I'm struggling to come to terms with
measuring the Screen innerWidth and innerHeight
values in IE.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */var is_ie5_5up = ( true )// -------------------------------------------------------------------// -------------------------------------------
// Global variables
// -------------------------------------------var gIntrvlSSRepaint ; // the timer for repainting
var gIntrvlSSListen ; // keep checking to see if time has elapsed and required to start the SS
var gIntrvlSSElapsed ; // since last activity
var counter = 0 ; // MAGIC?var gWidth, gHeight ; // store the screen dimensionsvar LINE_WIDTH = 90 ;
var ACTIVITY_TIMEOUT = 15000 ; // 15 seconds
var CHECK_ACTIVITY_INTERVAL = 1000 ; // 1 second
var REPAINT_INTERVAL = 100 ;
var SCROLLBAR_WIDTH = 0
var TASKBAR_HEIGHT = 0// If you already do stuff in a onload event handler, then you must
// call gfnSSInitialize() from there, otherwise just leave this code
// as-is and it will call itself
var gobjScreenSaver ;function screenSaverInit()
{
if (is_ie5_5up)
{
new ScreenSaver() ;
gobjScreenSaver.Init() ;
CalcScreenAvail()
gIntrvlSSElapsed = new Date().valueOf() ;
gIntrvlSSListen = setInterval( "activityChecker()", CHECK_ACTIVITY_INTERVAL ) ;
}
}// If you need to do stuff in these handlers as well, just add
// you own stuff in, but be sure to still call the ScreenSaver helpers.
window.onload = function() { screenSaverInit(); } // Instantiate the ScreenSaver
document.onkeypress = function() { activityMonitor(); }
document.onmousemove = function() { activityMonitor(); }
document.onmousedown = function() { activityMonitor(); }
document.onmouseup = function() { activityMonitor(); }
window.onresize = function() { CalcScreenAvail(); }// -------------------------------------------
// Helper functions etc.
// -------------------------------------------// used from several sections
function CalcScreenAvail()
{
gWidth = document.body.clientWidth;
gHeight = document.body.clientHeight;
if(!(typeof(gobjScreenSaver) == 'undefined'))
{
try
{
gobjScreenSaver.SetScreenSize()
}
catch(e){
// possibly route to an exception handler
}
}
}// Event Listener - called on a keypress and mousemove
function activityMonitor()
{
if(!(typeof(gobjScreenSaver) == 'undefined'))
{
try
{
gIntrvlSSElapsed = new Date().valueOf()
if(gobjScreenSaver.IsActive && !(gobjScreenSaver.IsPreview))
gobjScreenSaver.Stop() ;
}
catch(e){
// possibly route to an exception handler
}
}
}// called on a timer to invoke (Start) the screensaver
function activityChecker()
{
var tmp = new Date().valueOf()
if(((tmp - gIntrvlSSElapsed) > ACTIVITY_TIMEOUT) && !(gobjScreenSaver.IsActive))
{
gobjScreenSaver.Start()
}
}// -------------------------------------------------------------------document.writeln('<style>');
document.writeln('#myLine')
document.writeln('{')
document.writeln('position: absolute ;')
document.writeln('top: 100px ;')
document.writeln('left: 200px ;')
document.writeln('width: 100px ;')
document.writeln('height: 2px ;')
document.writeln('line-height: 2px ;')
document.writeln('overflow: hidden ;')
document.writeln('z-index: 3099 ;')
document.writeln('}')
document.writeln('#myScreensaver')
document.writeln('{')
document.writeln('position: absolute ;')
document.writeln('top: 0px ;')
document.writeln('left: 0px ;')
document.writeln('z-index: 90 ;')
document.writeln('}')
document.writeln('<\/style>')
document.writeln('<DIV Id="myScreensaver"></DIV>') ;// -------------------------------------------
// Line and Screensaver Classes
// -------------------------------------------function Line(obj, xpos, ypos)
{
this.Started = 0
this.Element = obj
this.xpos = xpos
this.ypos = ypos
this.decreaseX = true
this.decreaseY = true
this.Reset = function()
{
this.Started = 0
this.xpos = 200
this.ypos = 100
this.Element.style.display = 'none'
this.decreaseX = true
this.decreaseY = true
}
}
{
gobjScreenSaver = this
var oarrShapes = new Array() ; // the array of Shape Objects
this.IsActive = false ; // When the screensaver is on
this.IsPreview = false ; // IsPreview is a small buffer that allows users to view the screensaver from a button click (or whatever)
// Color stuff
this.COLOR_BASE = 0
this.MAX_ITEMS = 60
this.INCR = (255 / parseInt(this.MAX_ITEMS / 3))
// Create the Color Enumerated Type
this.Color = new Array() ;
this.Color.Red = this.COLOR_BASE ;
this.Color.Green = this.COLOR_BASE ;
this.Color.Blue = this.COLOR_BASE ;
this.Init = function ()
{
var curLine ;
var bg = document.getElementById("myScreensaver")
bg.style.backgroundColor = "Black" ;
bg.style.position = "absolute"
bg.style.display = "none"
this.Bg = bg
// Generate the initial oarrShapes
for (var i=0; i<=this.MAX_ITEMS; i++)
{
// initialize the oarrShapes
this.UpdateColorValues(i)
curLine = document.createElement("DIV")
with(curLine) {
id = "myLine"
style.backgroundColor = "rgb(" + this.Color.Red + "," + this.Color.Green + "," + this.Color.Blue + ")" //colors[i] ;
style.zIndex = 201 - i ;
style.display = "none"
}
document.body.appendChild( curLine )
curLine.style.pixelWidth = LINE_WIDTH
oarrShapes[i] = new Line(curLine, 200, 100)
}
}
// called on init and onresize to ensure that canvass size matches
// screen size
this.SetScreenSize = function()
{
this.Bg.style.height = ( gHeight - TASKBAR_HEIGHT ) ;
this.Bg.style.width = ( gWidth - SCROLLBAR_WIDTH ) ;
}
this.Start = function( isPreviewMode )
{
// if the user has specified IsPreviewMode set a delay
if( isPreviewMode ) this.IsPreview = true ;
this.Bg.style.display = ""
for (var i=0; i<=oarrShapes.length-1; i++)
oarrShapes[i].Element.style.display = ""
this.IsActive = true ;
startCounter("gobjScreenSaver.Animate()",REPAINT_INTERVAL) ;
}
this.Stop = function()
{
stopCounter(gIntrvlSSRepaint) ;
this.Bg.style.display = "none"
for (var i=0; i<=oarrShapes.length-1; i++)
oarrShapes[i].Reset()
this.IsActive = false ;
counter = 0 ;
}
// helper function used to cycle though the Red/Green/Blue colors
this.UpdateColorValues = function(counter)
{
this.Color.Red = this.COLOR_BASE
this.Color.Green = this.COLOR_BASE
this.Color.Blue = this.COLOR_BASE
if (counter <= parseInt(this.MAX_ITEMS / 3))
{
this.Color.Red = 255 -
(parseInt(counter % parseInt(this.MAX_ITEMS / 3)) * this.INCR)
}
else if (counter <= parseInt(parseInt(this.MAX_ITEMS / 3) * 2))
{
this.Color.Green = 0 +
(parseInt(counter % parseInt(this.MAX_ITEMS / 3)) * this.INCR)
}
else
{
this.Color.Blue = 255 -
(parseInt(counter % parseInt(this.MAX_ITEMS / 3)) * this.INCR)
}
}
/* Animate enumerates the oarrShapes collection and sequentially
toggles their xpos/ypos position on the screen */
this.Animate = function()
{
var curLine ;
var bContinue = true ;
for (var i=0; i<=oarrShapes.length-1; i++)
{
curLine = oarrShapes[i]
// stagger the line starting process...
if( curLine.Started == 0 ) { curLine.Started = 1; bContinue = false ; }
curLine.Element.style.left = curLine.xpos ;
curLine.Element.style.top = curLine.ypos ;
// If we are near the boundaries then we
// need to toggle a switch so that the counter goes in the
// reverse direction ...
if(curLine.xpos < 10) curLine.decreaseX = false ;
if(curLine.xpos > ( gWidth - ( SCROLLBAR_WIDTH + 20 ) ) - LINE_WIDTH ) curLine.decreaseX = true ;
if(curLine.ypos < 20) curLine.decreaseY = false ;
if(curLine.ypos > ( gHeight - ( TASKBAR_HEIGHT + 20 ) ) ) curLine.decreaseY = true ;
// Now apply the actual counter increment/decrement ...
if(curLine.decreaseX) {
curLine.xpos = curLine.xpos - 20 ;
} else {
curLine.xpos = curLine.xpos + 20 ;
}
if(curLine.decreaseY) {
curLine.ypos = curLine.ypos - 13 ;
} else {
curLine.ypos = curLine.ypos + 13 ;
}
// we stagger the line starting process
if(!(bContinue)) break ;
}
// explicitly set this to false, by the time we get to here
// the required delay has passed
this.IsPreview = false ;
}
}function startCounter(fn,interval)
{
gIntrvlSSRepaint = window.setInterval(fn,interval) ;
}function stopCounter(timer)
{
window.clearInterval(timer) ;
}
//这是个屏幕保护类
//调用方法,参考下吧
<html>
<head>
<script src="ScreenSaver.js" language="javascript"></script>
</head>
<body onload="screenSaverInit();gobjScreenSaver.Start(true);">
<input type=button value=start onclick="gobjScreenSaver.Start(true);">
</body >
</html>
<script language="JavaScript">
var startdate;
var curdate;
function init(){
document.onmousemove=function(){startdate=new Date();}
document.onclick=function(){startdate=new Date();}
document.onscroll=function(){startdate=new Date();}
}
function popup(){
curdate=new Date();
second=(curdate.getTime()-startdate.getTime())/1000;
if (second>2){
alert("超过时间!");
}
}
setInterval("popup()",1000);
</script>
<body onLoad="init()">
</body>
如果用你的方法"超出时间"改成弹出一个新页面呢??
还有一个就是改成新页面的话会不会一直弹出呢?
用session 和 <meta http-equiv=Refresh content=900;url=pb2.asp> 不过好像后面这种不能打开新窗口.
定义一个全局变量比如a
if (a==null){
a=window.open(...);
}
这样应该就不会重复弹了
<script language="JavaScript">
var startdate;
var curdate;
var flag;
function init(){
document.onmousemove=function(){startdate=new Date();}
document.onclick=function(){startdate=new Date();}
document.onscroll=function(){startdate=new Date();}
}
function popup(){
curdate=new Date();
second=(curdate.getTime()-startdate.getTime())/1000;
if (second>2){
try{
var test=flag.document;
}
catch(e){
flag=window.open("url.htm");
}
}
}
setInterval("popup()",1000);
</script>
<body onLoad="init()">
</body>