从桌面打开文件到弹出窗口

3

我是一名完全的HTML编码初学者,我想知道是否可以直接在页面中编写窗口大小和其他属性。我来解释一下。

我正在制作一个计算器,我希望在我的桌面上运行HTML文件。一切都很好,但它会在浏览器中启动,在那里其他选项卡也已经打开了。我希望它在一个小弹出窗口中运行,没有状态栏、书签栏,并且有固定的窗口大小。

编辑:

代码本身

<!doctype html>
<html>
<head><center>Kalkuraatur</center>
<Title>Javascripti Kalkulaator</title>
<script type="text/javascript">
    if(window.name != "mypopup") {
        window.open(document.location.href,'mypopup', 'left=300,top=200,width=200,height=200,toolbar=0,status=0,location=0,menubar=0,scrollbars=0,titlebar=0'); var child = window.open(...; child.focus();
        window.close();
    }
</script>
<script type="text/javascript">
function arvuta ()
{
kalku.sisend.value = eval(kalku.sisend.value)
}
function Bspace(sisend)
{
kalku.sisend.value = kalku.sisend.value.substring(0, kalku.sisend.value.length - 1)
}
</script>
</head>
<body>
<center>
<form name="kalku">
<table border=2>
<tr><td>
<input type="text" name="sisend" size="21">
<br>
</td></tr>
<tr><td>
<input type="button" name="seitse" value=" 7 " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '7'">
<input type="button" name="kaheksa" value=" 8 " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '8'">
<input type="button" name="yheksa" value=" 9 " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '9'">
<input type="button" name="ykstagasi" value="del" style="height: 22px; width: 30px" onclick="Bspace(this)">
<input type="button" name="kustuta" value=" C " style="height: 22px; width: 30px" onclick="kalku.sisend.value = ''">
<br>
<input type="button" name="neli" value=" 4 " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '4'">
<input type="button" name="viis" value=" 5 " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '5'">
<input type="button" name="kuus" value=" 6 " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '6'">
<input type="button" name="jaga" value=" ÷ " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '/'">
<input type="button" name="korruta" value=" x " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '*'">
<br>
<input type="button" name="yks" value=" 1 " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '1'">
<input type="button" name="kaks" value=" 2 " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '2'">
<input type="button" name="kolm" value=" 3 " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '3'">
<input type="button" name="lahuta" value=" - " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '-'">
<input type="button" name="plus" value=" + " style="height: 22px; width: 30px" onclick="kalku.sisend.value += '+'">
<br>
<input type="button" name="null" value=" 0 " style="height: 23px; width: 64px" onclick="kalku.sisend.value += '0'">
<input type="button" name="koma" value=" , " style="height: 22px; width: 30px" onclick="kalku.sisend.value += ','">
<input type="button" name="v6rdub" value=" = " style="height: 22px; width: 64px" onclick="arvuta ()">
</td></tr>
</form>
</center>
</body>
</html>

你需要使用JavaScript。尝试使用http://www.textfixer.com/html/javascript-pop-up-window.php,看看是否有帮助。 - Gaurav Sharma
Calc作为计算器,文件没有上传到任何地方。它在我的电脑里。 - Jakwobo
3个回答

1

如果您愿意配置/处理弹出窗口拦截器,您可以将此作为html文档头的第一项添加:

<script type="text/javascript">
    if(window.name != "mypopup") {
        window.open(document.location.href,'mypopup', 'left=300,top=200,width=200,height=200,toolbar=0,status=0,location=0,menubar=0,scrollbars=0,titlebar=0');
        window.open('', '_self', ''); // chrome bug
        window.close();
    }
</script>

尚未测试,但可以尝试以下内容以进行焦点设置:
<script type="text/javascript">
    if(window.name != "mypopup") {
        var childWindow = window.open(document.location.href,'mypopup', 'left=300,top=200,width=200,height=200,toolbar=0,status=0,location=0,menubar=0,scrollbars=0,titlebar=0');
        //like this
        childWindow.focus();
        window.open('', '_self', ''); // chrome bug
        window.close();
    } else {
        //or like this
        window.focus();
    }
</script>

我该如何设置它始终显示在最上层? - Jakwobo
你可以在子窗口上调用 focus() 方法,尝试创建 else 语句并将其放在 window.focus() 中,或者你可以将 window.open 函数的返回值分配给一个变量,例如 var child = window.open(...); child.focus(); - cbayram
我允许Chrome打开我的文件中的弹出窗口,但它不会打开它们。在IE中,我必须允许脚本,但它可以工作。非常感谢。 - Jakwobo
我已经编辑了您的帖子,以更正您代码中的粘贴错误。 - cbayram

0
据我所知,浏览器窗口的大小是无法通过HTML更改的。但您可以使用JavaScript和/或jQuery编写自己的弹出窗口。
在用户最终着陆的网页上添加一个“点击运行计算器”的链接。当他们点击该链接时,启动您自定义的弹出窗口。
这里是一个正在运行的示例,以便更好地理解我的意思。

我已经得到了类似的东西,但我希望它可以立即在窗口中打开页面,而无需单击任何东西。 - Jakwobo

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接