我想在网页上创建一个链接,该链接将关闭浏览器中当前活动的选项卡而不关闭浏览器中的其他选项卡.
当用户单击关闭链接时,将出现一条警告消息,要求用户使用"是"和"否"两个按钮进行确认.如果用户单击"是",则关闭该页面,如果"否",则不执行任何操作.
怎么做到呢?有什么建议?
如何在未收到" 是否要关闭此窗口提示"的情况下关闭浏览器窗口?
我使用该window.close();功能时出现提示.
当我试图通过window.close()Javascript 的方法关闭窗口时,我总是遇到问题,而浏览器在控制台上显示以下消息:
"Scripts may close only the windows that were opened by it."
Run Code Online (Sandbox Code Playgroud)
这发生在页面的每个部分.我可以直接使用链接,按钮或脚本运行此命令,但始终显示此消息.
我试图替换window.close();下面的函数(或其变体)的方法,但没有发生任何事情:
window.open('', '_self', '');
window.close();
Run Code Online (Sandbox Code Playgroud) <?php
/* ... SQL EXECUTION TO UPDATE DB ... */
?>
<form method = "post"
action = "<?=$_SERVER['php_self']?>"
onSubmit= "window.close();">
...
<input type="submit" value="submit" />
<input type="reset" value="reset" />
</form>
Run Code Online (Sandbox Code Playgroud)
我想在提交表格后关闭页面.运行上面的代码后,单击提交按钮后页面将关闭,但SQL不会执行.
谁能帮我?提前致谢!
我已经在shinyapps.io中部署了一个应用程序并且工作正常.
我运行的应用程序只有5分钟,但当我检查指标时,它显示运行时间约为0.7小时.我发现有一个15分钟的默认空闲时间,我已经改为5分钟(最小).我还注意到,即使在关闭闪亮应用程序的浏览器窗口后,它仍然显示应用程序在我的仪表板中运行.
我假设应用程序在浏览器窗口关闭时不会停止运行,只有在满足空闲时间条件时它才会停止.
有没有办法在浏览器窗口关闭时停止闪亮的应用程序?以下代码是否适用于此实例?
session$onSessionEnded(function() {
stopApp()
})
Run Code Online (Sandbox Code Playgroud) 我在test.js中有以下代码,它在</ body>之前运行:
alert('stovetop');
alert(greasy);
Run Code Online (Sandbox Code Playgroud)
我在test.user.js中有以下代码:
(function () {
'use strict';
var greasy = 'greasy variable';
document.title = 'greasy title';
}());
Run Code Online (Sandbox Code Playgroud)
'炉灶'得到警报,所以我知道页面javascript工作,并document.title得到更改,所以我知道脚本javascript工作.但是,在网页上我收到错误:
错误:ReferenceError:未定义greasy源文件:/test.js
如何从网页上访问由Greasemonkey设置的变量,反之亦然?
请帮助有关关闭当前窗口的Java脚本。这是我的代码,它不起作用。
<input type="button" class="btn btn-success"
style="font-weight: bold;display: inline;"
value="Close"
onclick="closeMe()">
function closeMe()
{
window.opener = self;
window.close();
}
Run Code Online (Sandbox Code Playgroud)
我尝试了这个,但是还是不行
var win = window.open(“”,”_self”);
win.close();
Run Code Online (Sandbox Code Playgroud) 我正在尝试实施Google Oauth功能.这就是我的程序运行方式.首先,index.jsp文件运行并打开一个页面,如下所示:

我的index.jsp代码是:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Website</title>
</head>
<style>
h1 {
font-family: Bookman;
font-size: 150px;
font-style: normal;
font-variant: normal;
font-weight: 800;
line-height: 26.4px;
text-color: white;
text-align: center;
}
p {
font-family: Bookman;
font-size: 50px;
font-style: normal;
font-variant: normal;
font-weight: 800;
line-height: 26.4px;
text-color: white;
text-align: center;
}
.main_background{
background-image: url("img/main_page_background.jpg");
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
<body class=main_background>
<h1 …Run Code Online (Sandbox Code Playgroud)我希望我的Web应用程序在没有菜单栏,地址栏等的窗口中运行.我有一个Default.html页面,在此页面中我单击"运行应用程序"按钮,首先在另一个窗口中打开我的应用程序window.open,然后关闭使用window.openwith _self参数打开"AutoClose.html"的当前窗口
default.html中
<html>
<head>
<script type="text/javascript">
function runApp() {
// Open my application
window.open('Application.html', null, 'status:no;dialogHide:true;help:no;scroll:yes;center=yes;');
// Close this window
window.open('AutoClose.html', '_self');
}
</script>
</head>
<body>
<input type="button" value="Run Application" onclick="runApp();" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
AutoClose.html
<html>
<head>
<script type="text/javascript">
window.close();
</script>
</head>
<body></body>
</html>
Run Code Online (Sandbox Code Playgroud)
我的应用程序应支持IE,Firefox和Chrome,我的代码在IE和Chrome上工作正常,但由于"脚本可能无法关闭脚本未打开的窗口"警告,因此无法关闭Firefox上的第一个窗口.在Firefox上它打开AutoClose.html但是window.close()在此页面中调用只会导致"脚本可能无法关闭脚本未打开的窗口"警告并且窗口未关闭.顺便说一句,我的应用程序窗口打开没有任何问题(没有问题).
看来,使用window.open()带有_self参数的伎俩Firefox没有工作.因为我的目标是在没有菜单栏,地址栏等的窗口中运行应用程序.
window.open()(至少对于Firefox)?然后我不需要跑window.close() window.close()在Firefox上有没有办法让"使用javascript的脚本无法打开的窗口"工作?提前致谢.
更新:这是一个银行应用程序,我只是一个开发人员而不是决策者.换句话说,某种分析师希望应用程序以这种方式工作.我不是在质疑它.所以"你要做的全部事情是完全错误的"答案不会真正有用.
我让Chrome浏览器在Android上安装了PWA-安装完成后,我想自动关闭从中安装它的浏览器窗口,然后打开PWA(这样用户就不会继续在浏览器窗口中以为他们正在使用PWA)-这可能吗?
我正在尝试编写一个可以在 Firefox 5.0 上运行的 JavaScript 函数。我需要页面完全加载,然后关闭。我想做的是:
var temp = window.open(link);
temp.window.onload = function () {
temp.window.close();
}
Run Code Online (Sandbox Code Playgroud)
但到目前为止,它所做的只是打开新选项卡,但没有关闭它。
有什么方法可以成功实现这一点吗?
我有一个倒计时的网页,并重定向到上一页,效果很好,但我想要关闭页面(当前浏览器选项卡),而不是重定向到上一页.消失.自毁.我试过替换我的重定向history.go(-1),window.close()但它没有用.
JS:
var countdownfrom=9
var currentsecond=document.redirect.redirect2.value=countdownfrom+1
function countredirect(){
if (currentsecond!=1){
currentsecond-=1
document.redirect.redirect2.value=currentsecond
}
else{
history.go(-1)
return
}
setTimeout("countredirect()",1000)
}
countredirect()
Run Code Online (Sandbox Code Playgroud)
HTML:
<form name="redirect">
<h1>Oops! I think you meant to use a URL...</h1>
<h2>this page will self destruct in</h2>
<form>
<input type="text" size="1" name="redirect2">
</form>
<h2>seconds</h2>
<h3>Go back to where you came from and try again!</h3>
Run Code Online (Sandbox Code Playgroud)
html看起来不正确,你甚至可以将表单嵌套在另一个表单中吗?它工作正常.
<h1>Oops! I think you meant to use a URL...</h1>
<h2>this page will self destruct in</h2>
<form name="redirect">
<input type="text" …Run Code Online (Sandbox Code Playgroud) 我正在使用 window.open() 打开一个新窗口。如果我在此页面上不执行任何其他操作,并单击“关闭窗口”链接,则窗口将关闭。这很有效;但是,如果我在页面之间导航(所有页面都在同一域下), window.close() 将不再起作用。
有没有办法来解决这个问题?
<a href="###" target="_blank">
Run Code Online (Sandbox Code Playgroud)
<a href="javascript:void(0)" onclick="window.close()">close</a>
Run Code Online (Sandbox Code Playgroud)
<select onchange="if (this.value) window.location.href=this.value">和标准<a href="####">标签
我是否需要以某种方式导航此窗口中的链接才能仍然保持我的window.close()能力?