我正在维护一个大型应用程序。在某些方面,我必须检查当前窗口是弹出窗口(使用window.open()打开)还是新窗口(使用target =" _blank"打开的新选项卡或窗口)。
这是我的问题的一个例子:
function CancelOutOfPage(cancelPath) {
if (cancelPath != null && cancelPath != "" && window.opener == null) {
location.href = cancelPath;
} else if (referrerUrl != "" && window.opener == null) {
// Just go back
location.href = referrerUrl;
} else {
// It is a popup, close it.
// MY PROBLEM IS HERE. IF THE WINDOW IS NOT A POPUP, BUT A AN OPENED PAGE
// THE WHOLE WINDOW WILL CLOSE
window.close();
}
}
答案 0 :(得分:1)
你可以在打开弹出窗口时设置一个全局变量,然后你知道如果变量是一个真值,它就是一个弹出窗口 - 如果它是undefined
它将是false
:
在通话页面中:
var popupWindow = window.open(page);
popupWindow.isPopup = true;
在新窗口中:
if (window.isPopup) {
window.close();
}
当您使用弹出窗口打开时,您也可以设置window
的名称。 window.open函数为名称提供第二个参数,后跟可选的窗口功能。
在通话页面中:
window.open("test.html", "Test Popup");
在新窗口中:
if (window.name.length) {
window.close();
}
答案 1 :(得分:0)
打开窗口时,可以在窗口上显示标记。
//in window from which you open new window
var w = window.open('');
w.someFlag = true;
//in opened window
console.log(window.someFlag);
if (window.someFlag){
//do what you want
}
答案 2 :(得分:0)
您可以通过向options.SigningCertificate = LoadCertificate();
public X509Certificate2 LoadCertificate()
{
string thumbPrint = "104A19DB7AEA7B438F553461D8155C65BBD6E2C0";
// Starting with the .NET Framework 4.6, X509Store implements IDisposable.
// On older .NET, store.Close should be called.
using (var store = new X509Store(StoreName.My, StoreLocation.LocalMachine))
{
store.Open(OpenFlags.ReadOnly);
var certCollection = store.Certificates.Find(X509FindType.FindByThumbprint, thumbPrint, validOnly: false);
if (certCollection.Count == 0)
throw new Exception("No certificate found containing the specified thumbprint.");
return certCollection[0];
}
}
提供第二个参数来设置新name
的{{1}},例如;
window
打开window.open()
,
var w = window.open("url", "__blank__")