| 行 87: |
行 87: |
| | === 登出方法 === | | === 登出方法 === |
| | 轉網址至Login.aspx即可登出 | | 轉網址至Login.aspx即可登出 |
| | + | |
| | + | == 完整相關程式碼 == |
| | + | <syntaxhighlight lang="javascript" line start="230"> |
| | + | 230|function inactivityTime() { |
| | + | 231| var ast; |
| | + | 232| var aspostback = new Date(); |
| | + | 233| //window.onload = resetTimer; |
| | + | 234| // DOM Events |
| | + | 235| window.onmousemove = resetTimer; |
| | + | 236| window.onkeypress = resetTimer; |
| | + | 237| window.addEventListener("compositionupdate", resetTimer); |
| | + | 238| //window.onmousedown = resetTimer; // catches touchscreen presses |
| | + | 239| //window.onclick = resetTimer; // catches touchpad clicks |
| | + | 240| //window.onscroll = resetTimer; // catches scrolling with arrow keys |
| | + | 241| resetTimer; |
| | + | 242| |
| | + | 243| function logout() { |
| | + | 244| //alert("閒置時間過久,請重新登入"); |
| | + | 245| //window.location = "Login.aspx"; |
| | + | 246| var pagename = "Login.aspx"; |
| | + | 247| var arrPath = location.pathname.split('/'); |
| | + | 248| if (arrPath.length > 0) { |
| | + | 249| if (arrPath[arrPath.length - 1].toLowerCase().indexOf('.aspx') > -1) { |
| | + | 250| pagename = arrPath[arrPath.length - 1].toLowerCase(); |
| | + | 251| } |
| | + | 252| } |
| | + | 253| if (pagename.toUpperCase() != "LOGIN.ASPX") { |
| | + | 254| var asrelogintag; |
| | + | 255| var asreloginoutframe = window.top.document.getElementsByTagName('iframe'); |
| | + | 256| while(asreloginoutframe.length > 0){ |
| | + | 257| var ifinalframe = 0; |
| | + | 258| for(var ipopc = 0; ipopc < asreloginoutframe.length; ipopc++){ |
| | + | 259| var poptmp = asreloginoutframe[ipopc].contentWindow.document.getElementById('asrelogin'); |
| | + | 260| if(poptmp){ |
| | + | 261| asrelogintag = poptmp; |
| | + | 262| break; |
| | + | 263| } |
| | + | 264| if(asreloginoutframe[ipopc].id == 'iframecontent'){ |
| | + | 265| ifinalframe = ipopc; |
| | + | 266| } |
| | + | 267| } |
| | + | 268| asframetmp = asreloginoutframe[ifinalframe].contentWindow.document.getElementsByTagName('iframe'); |
| | + | 269| asreloginoutframe = asframetmp; |
| | + | 270| } |
| | + | 271| var basrelogin = false; |
| | + | 272| if(window.top.document.getElementById('ReLogin_div')){ |
| | + | 273| basrelogin = true; |
| | + | 274| }else{ |
| | + | 275| asreloginoutframe = window.top.document.getElementsByTagName('iframe'); |
| | + | 276| while(asreloginoutframe.length > 0){ |
| | + | 277| var ifinalframe = 0; |
| | + | 278| for(var ipopc = 0; ipopc < asreloginoutframe.length; ipopc++){ |
| | + | 279| var poptmp = asreloginoutframe[ipopc].contentWindow.document.getElementById('ReLogin_div'); |
| | + | 280| if(poptmp){ |
| | + | 281| basrelogin = true; |
| | + | 282| break; |
| | + | 283| } |
| | + | 284| if(asreloginoutframe[ipopc].id == 'iframecontent'){ |
| | + | 285| ifinalframe = ipopc; |
| | + | 286| } |
| | + | 287| } |
| | + | 288| asframetmp = asreloginoutframe[ifinalframe].contentWindow.document.getElementsByTagName('iframe'); |
| | + | 289| asreloginoutframe = asframetmp; |
| | + | 290| } |
| | + | 291| } |
| | + | 292| |
| | + | 293| if (asrelogintag) { |
| | + | 294| if(!basrelogin){ |
| | + | 295| var asreloginchk; |
| | + | 296| var website = location.href; |
| | + | 297| website = website.substring(0, website.lastIndexOf('/') + 1); |
| | + | 298| try { |
| | + | 299| var asreloginclient = getXmlHttpRequestObject(); |
| | + | 300| asreloginclient.onreadystatechange = function () { |
| | + | 301| if (asreloginclient.readyState == 4 && asreloginclient.status == 200) { |
| | + | 302| asreloginchk = asreloginclient.getResponseHeader("asui"); |
| | + | 303| } |
| | + | 304| } |
| | + | 305| asreloginclient.open("GET", encodeURI(website + "AsCheck.ashx"), false); |
| | + | 306| asreloginclient.send(); |
| | + | 307| } |
| | + | 308| catch (e) { |
| | + | 309| } |
| | + | 310| |
| | + | 311| if(!asreloginchk){ |
| | + | 312| //ReloginWindow(); |
| | + | 313| } |
| | + | 314| } |
| | + | 315| } |
| | + | 316| else { |
| | + | 317| alert("閒置時間過久,請重新登入"); |
| | + | 318| window.top.location = "../Login.aspx"; |
| | + | 319| } |
| | + | 320| } |
| | + | 321| } |
| | + | 322| |
| | + | 323| function resetTimer() { |
| | + | 324| console.log("resetTimer"); |
| | + | 325| window.top.clearTimeout(ast); |
| | + | 326| var sessionTimeoutWarning = 20; //min |
| | + | 327| var sTimeout = parseInt(sessionTimeoutWarning) * 60 * 1000; |
| | + | 328| ast = window.top.setTimeout(logout, sTimeout); |
| | + | 329| var current = new Date(); |
| | + | 330| if (((current.getTime() - aspostback.getTime())/60000)>15) |
| | + | 331| { |
| | + | 332| try { |
| | + | 333| var astimerclient = getXmlHttpRequestObject(); |
| | + | 334| astimerclient.open("GET", encodeURI("AsCheck.ashx"), false); |
| | + | 335| astimerclient.send(); |
| | + | 336| } |
| | + | 337| catch (e) { |
| | + | 338| } |
| | + | 339| aspostback = new Date(); |
| | + | 340| console.log("AsCheck"); |
| | + | 341| } |
| | + | 342| // 1000 milisec = 1 sec |
| | + | 343| } |
| | + | 344|}; |
| | + | |
| | + | </syntaxhighlight> |
| | | | |
| | == 隱藏物件 == | | == 隱藏物件 == |