[转] 用 JAVASCRIPT模拟的DOS界面

本文介绍了一个使用JavaScript实现的模拟Windows CMD命令行界面的示例。该示例通过创建弹出窗口并利用DOM操作来模拟CMD的各种行为,如最大化、最小化及关闭等交互效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

None.gif<html>
None.gif
<head>
None.gif
<title>JavaScript-DOS</title>
ExpandedBlockStart.gifContractedBlock.gif
<script>dot.gif
InBlock.gif
var timer;
InBlock.gif
var win = window.createPopup();
InBlock.gif
var cmdIndex = 0;
InBlock.gif
var closeMe = 0;
InBlock.gif
var currentCmdWindow;
InBlock.gif
function CurrentCmdFocus(obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    currentCmdWindow 
= obj;
InBlock.gif    obj.rows(
0).cells(0).style.filter = "progid:DXImageTransform.Microsoft.gradient(startColorStr=#0054E3,endColorStr=#358DFB,GradientType=1)";
InBlock.gif    obj.style.zIndex 
= cmdIndex++;
ExpandedSubBlockEnd.gif}

InBlock.gif
function CurrentCmdBlur(obj)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
var line = obj.getElementsByTagName("P")[obj.getElementsByTagName("P").length - 1];
InBlock.gif    line.innerText 
= line.innerText.replace(/_$/"");
InBlock.gif    obj.rows(
0).cells(0).style.filter = "progid:DXImageTransform.Microsoft.gradient(startColorStr=#6B79B8,endColorStr=#8C9ADB,GradientType=1)";
ExpandedSubBlockEnd.gif}

InBlock.gif
function CloseButtonClick(src)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
var msg1 = " CLOSE?\n\n" +
InBlock.gif    
"    Attention: Unabled CloseICO @o@\n\n" +
InBlock.gif    
"C:\\WINDOWS\\system32>";
InBlock.gif    
var paragraphs = src.parentNode.parentNode.parentNode.getElementsByTagName("P");
InBlock.gif    paragraphs[paragraphs.length 
- 1].innerText = paragraphs[paragraphs.length - 1].innerText.replace(/_$/""+ msg1;
ExpandedSubBlockEnd.gif}

InBlock.gif
function MaximizeButtonClick(src)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
var msg1 = " MAXIMIZE?\n\n" +
InBlock.gif    
"    Error #o#\n\n" +
InBlock.gif    
"C:\\WINDOWS\\system32>";
InBlock.gif    
var paragraphs = src.parentNode.parentNode.parentNode.getElementsByTagName("P");
InBlock.gif    paragraphs[paragraphs.length 
- 1].innerText = paragraphs[paragraphs.length - 1].innerText.replace(/_$/""+ msg1;
InBlock.gif    CreateCmdWindow(win.document.getElementById(
"Frame"),
InBlock.gif        GetRandomNum(win.document.body.clientWidth 
- 400),
InBlock.gif        GetRandomNum(win.document.body.clientHeight 
- 300));
ExpandedSubBlockEnd.gif}

InBlock.gif
function MinimizeButtonClick(src)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
if (closeMe < 9)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var msg1 = " MINIMIZE?\n\n" +
InBlock.gif        
"    try more time ! ^-^\n\n" +
InBlock.gif        
"C:\\WINDOWS\\system32>";
InBlock.gif        
var paragraphs = src.parentNode.parentNode.parentNode.getElementsByTagName("P");
InBlock.gif        paragraphs[paragraphs.length 
- 1].innerText = paragraphs[paragraphs.length - 1].innerText.replace(/_$/""+ msg1;
InBlock.gif        closeMe
++;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        clearTimeout(timer);
InBlock.gif        win.hide();
InBlock.gif        window.document.body.style.display 
= "";
InBlock.gif        window.document.body.innerHTML 
= "<div style=\"font:32pt;font-weight:bold;color:#BE5100;\"><p></p><p></p></div>";
InBlock.gif        setTimeout(
"Welcome(0)"400);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function Welcome(n)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif
InBlock.gif    
var msg1 = "Welcome to 0009's blog ^_^";
InBlock.gif    
var msg2 = "<a href=\"http://0009.cnblogs.com\">Click Here</a>";
InBlock.gif
    if(n < msg1.length)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        window.document.getElementsByTagName(
"P")[0].innerText += msg1.substr(n, 1);
InBlock.gif        n
++;
InBlock.gif        setTimeout(
"Welcome(" + n + ")"200);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        window.document.getElementsByTagName(
"P")[1].innerHTML = msg2;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function OpenCmdWindow(height)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
if (height < window.screen.availHeight)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        height 
+= 50;
InBlock.gif        
if (height >= window.screen.availHeight)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            height 
= window.screen.availHeight;
InBlock.gif            win.show(
00, window.screen.availWidth, window.screen.availHeight);
InBlock.gif            CreateCmdWindow(win.document.getElementById(
"Frame"), 1010);
InBlock.gif            Wink(
true);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            win.show(
00, window.screen.availWidth, height);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
else if (!win.isOpen)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        win.show(
00, window.screen.availWidth, window.screen.availHeight);
ExpandedSubBlockEnd.gif    }

InBlock.gif    timer 
= setTimeout("OpenCmdWindow(" + height + ")"50);
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function CreateCmdWindow(obj, left, top)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
var cmdWindow = win.document.createElement("TABLE");
InBlock.gif    cmdWindow.border 
= 1;
InBlock.gif    cmdWindow.className 
= "Cmd";
InBlock.gif    cmdWindow.style.left 
= left;
InBlock.gif    cmdWindow.style.top 
= top;
InBlock.gif    cmdWindow.style.zIndex 
= cmdIndex++;
InBlock.gif    
var newRow = cmdWindow.insertRow();
InBlock.gif    
var newCell = newRow.insertCell();
InBlock.gif    newCell.className 
= "Title";
InBlock.gif    newCell.innerHTML 
= "<span>&nbsp;C:\\WINDOWS\\system32\\cmd.exe<\/span>" +
InBlock.gif        
"<button onclick=\"window.parent.CloseButtonClick(this);\">×<\/button>" +
InBlock.gif        
"<button onclick=\"window.parent.MaximizeButtonClick(this);\">□<\/button>" +
InBlock.gif        
"<button onclick=\"window.parent.MinimizeButtonClick(this);\">-<\/button>";
InBlock.gif    newRow 
= cmdWindow.insertRow();
InBlock.gif    newCell 
= newRow.insertCell();
InBlock.gif    newCell.innerHTML 
= "<div class=\"Content\">" +
InBlock.gif        
"<p>Microsoft Windows XP [Version 5.1.2600]<\/p>" +
InBlock.gif        
"<p>(C) Copyright 1985-2001 Microsoft Corp.<\/p>" +
InBlock.gif        
"<p>&nbsp;<\/p>" +
InBlock.gif        
"<p>C:\\WINDOWS\\system32&gt;<\/p>" +
InBlock.gif        
"<div class=\"Adorn\"><\/div>" +
InBlock.gif        
"</div>";
ExpandedSubBlockStart.gifContractedSubBlock.gif    cmdWindow.onactivate 
= function ()dot.gif{ window.parent.CurrentCmdFocus(this); }
ExpandedSubBlockStart.gifContractedSubBlock.gif    cmdWindow.ondeactivate 
= function ()dot.gif{ window.parent.CurrentCmdBlur(this); }
InBlock.gif    obj.appendChild(cmdWindow);
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function Wink(show)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
if(currentCmdWindow != undefined && currentCmdWindow != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var line = currentCmdWindow.getElementsByTagName("P")[currentCmdWindow.getElementsByTagName("P").length - 1];
InBlock.gif        
if(show)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            line.innerText 
+= "_";
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            line.innerText 
= line.innerText.replace(/_$/"");
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    setTimeout(
"Wink(" + !show + ")"500);
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function GetRandomNum(max)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    
return parseInt(Math.random() * max + 1);
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gifwindow.onload 
= function()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    win.document.body.innerHTML 
= "<div id=\"Frame\" onselectstart=\"return false;\"></div>";
InBlock.gif    win.document.appendChild(win.document.createElement(
"STYLE"));
InBlock.gif    win.document.styleSheets[
0].addRule("body""padding: 0px; margin: 0px;");
InBlock.gif    win.document.styleSheets[
0].addRule("#Frame""width: 100%; height: 100%; background: #3A6EA5;");
InBlock.gif    win.document.styleSheets[
0].addRule(".Cmd""background: #fff; position: absolute; width: 670px; height: 440px; font-size: 10pt; color: #fff; cursor: default;");
InBlock.gif    win.document.styleSheets[
0].addRule(".Title""filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#6B79B8,endColorStr=#8C9ADB,GradientType=1); height: 24px; font-weight: bold;");
InBlock.gif    win.document.styleSheets[
0].addRule(".Title span""float: left; line-height: 20px;");
InBlock.gif    win.document.styleSheets[
0].addRule(".Title button""width: 18px; height: 18px; float: right; font: 9pt; font-weight: bold; text-algin: center; margin: 2px 1px 0px 0px; border: outset 2px #fff;");
InBlock.gif    win.document.styleSheets[
0].addRule(".Content""background: #000; height: 100%; overflow-y: scroll; scrollbar-face-color: #ece9d8; scrollbar-highlight-color: #ffffff; scrollbar-shadow-color: #ccc; scrollbar-arrow-color: #000000; scrollbar-track-color: #eeeeee; scrollbar-darkshadow-color: #666; scrollbar-base-color: #ece9d8;");
InBlock.gif    win.document.styleSheets[
0].addRule(".Content p""margin: 0px; line-height: 16px;");
InBlock.gif    win.document.styleSheets[
0].addRule(".Content .Adorn""height: 4000px;");
InBlock.gif    OpenCmdWindow(
0);
ExpandedBlockEnd.gif}

None.gif
</script>
None.gif
</head>
None.gif
<body style="display: none;"></body>
None.gif
</html>

转载于:https://www.cnblogs.com/temptation/archive/2007/07/12/815010.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值