JavaScript强制以编程方式关闭选项卡?

JavaScript强制以编程方式关闭选项卡?,javascript,google-chrome,screen-scraping,Javascript,Google Chrome,Screen Scraping,我遇到了一个问题,一些网站无法以编程方式关闭: window.close() 在以下情况下失败: web/Stores.war/RAPIDStorefrontAssetStore/AJAXUserInterface/javascript/FDBrowse.js:301 Uncaught TypeError: Cannot read property 'style' of null at close (web/Stores.war/RAPIDStorefrontAssetStore/AJAXUs

我遇到了一个问题,一些网站无法以编程方式关闭:

window.close()
在以下情况下失败:

web/Stores.war/RAPIDStorefrontAssetStore/AJAXUserInterface/javascript/FDBrowse.js:301 Uncaught TypeError: Cannot read property 'style' of null
at close (web/Stores.war/RAPIDStorefrontAssetStore/AJAXUserInterface/javascript/FDBrowse.js:301)
at <anonymous>:1:8
web/Stores.war/RAPIDStorefrontAssetStore/AJAXUserInterface/javascript/FDBrowse.js:301未捕获类型错误:无法读取null的属性“style”
关闭时(web/Stores.war/RAPIDStorefrontAssetStore/AJAXUserInterface/javascript/FDBrowse.js:301)
在
虽然这也发生在其他人身上


我怎样才能强行关闭?close方法中运行的失败的是什么?一些调查显示,该文档未能在网站试图运行的脚本中找到某些文档元素,但如何在关闭之前阻止它运行任何内容?我试图将on_X方法设置为null,但未成功…

您面临的问题是,此网站已跳过默认的
窗口。请使用其他函数关闭
方法

要解决这个问题,您应该能够从母版页中的
Window.open()
返回的窗口对象调用原始的Window.close方法

var popup = window.open('...');
popup.close(); // should be the original Window.close method
但是,如果出于某种原因,您绝对希望从目标页面内部关闭此方法,则可以检索原始的
窗口。从iframe的
内容窗口关闭
方法,并在断开的页面上调用此方法

函数关闭(){
log(“在全局范围内声明不好”);
}
console.log(window.close.toString());
window.close();//我们的职能
var iframe=document.createElement('iframe');
iframe.style.cssText='不透明度:0;位置:绝对';
iframe.src='about:blank';
iframe.onload=函数(){
log(iframe.contentWindow.close.toString());
//你可以这样称呼它
iframe.contentWindow.close.call(窗口);
//即使它不会在这里工作,因为我们没有以编程方式打开页面
document.body.removeChild(iframe);
};

document.body.appendChild(iframe)
您面临的问题是,此网站已跳过默认的
窗口。请使用其他功能关闭
方法

要解决这个问题,您应该能够从母版页中的
Window.open()
返回的窗口对象调用原始的Window.close方法

var popup = window.open('...');
popup.close(); // should be the original Window.close method
但是,如果出于某种原因,您绝对希望从目标页面内部关闭此方法,则可以检索原始的
窗口。从iframe的
内容窗口关闭
方法,并在断开的页面上调用此方法

函数关闭(){
log(“在全局范围内声明不好”);
}
console.log(window.close.toString());
window.close();//我们的职能
var iframe=document.createElement('iframe');
iframe.style.cssText='不透明度:0;位置:绝对';
iframe.src='about:blank';
iframe.onload=函数(){
log(iframe.contentWindow.close.toString());
//你可以这样称呼它
iframe.contentWindow.close.call(窗口);
//即使它不会在这里工作,因为我们没有以编程方式打开页面
document.body.removeChild(iframe);
};

document.body.appendChild(iframe)
下面的语句
使用重新绑定
window.close()
原始窗口
,创建一个新窗口
,然后
关闭这两个窗口

(window.close = (w => w.close() || w.close)(window.open()))()

解释

已覆盖全局以关闭
任意元素

在浏览器中运行
console.log(window.close)
时,这一点很明显

console.log(window.close) // ƒ close(){document.getElementById("overlay").style.display="none"}
您引用的
错误是由于
window.close()
override
以及缺少
document.getElementById('overlay')
造成的

因此:
“无法读取null的属性“style”


因此:要以编程方式关闭
1800朵花
window.close()
必须重新启动(没有找到替代方法)。

下面的语句
使用重新绑定
window.close()
原始窗口
,然后
关闭
,创建一个新窗口

(window.close = (w => w.close() || w.close)(window.open()))()

解释

已覆盖全局以关闭
任意元素

在浏览器中运行
console.log(window.close)
时,这一点很明显

console.log(window.close) // ƒ close(){document.getElementById("overlay").style.display="none"}
您引用的
错误是由于
window.close()
override
以及缺少
document.getElementById('overlay')
造成的

因此:
“无法读取null的属性“style”


因此:要以编程方式关闭
1800朵花
window.close()
必须重新启动(除非找到替代方法)。

您只能使用
window.close()
一个用
window.open()
打开的窗口。是的,我知道。您的
window.close()在哪里正在执行?如果您正在开发一个chrome扩展,那么您可以使用ChromeAPI关闭一个特定的选项卡,该选项卡在任何情况下都应该有效。您还可以重定向到其他网站或随机URL,并让脚本关闭。我正在使用一些JS来刮取网页,加载另一个网站然后关闭的解决方案确实有效,因此我可能只需要使用…
console.log(window.close)
表明它们已覆盖默认的
window.close()
method您只能
window.close()
使用
window.open()
打开的窗口。是的,我知道。您的
window.close()在哪里正在执行?如果您正在开发一个chrome扩展,那么您可以使用ChromeAPI关闭一个特定的选项卡,该选项卡在任何情况下都应该有效。你也可以重定向到其他网站或随机URL,并让脚本关闭。我正在使用一些JS来抓取网页,加载另一个网站然后关闭的解决方案确实有效,所以我可能只需要使用…
console.log(window.close)
表明他们已经覆盖了d