Scripts May Close Only The Windows That Were Opened By Them

Find the data you need here

We provide programming data of 20 most popular languages, hope to help you!

Previous PostNext Post

"Scripts may close only the windows that were opened by it."
window.open('', '_self', '');
window.close();
"Scripts may close only the windows that were opened by it."
var customWindow = window.open('', '_blank', '');
    customWindow.close();
window.open("", '_self').window.close();
const closeWindow = () => {
 window.open(location.href, "_self", "");
 window.close()
}
window.open('your current page URL', '_self', '');
window.close();
"Scripts may close only the windows that were opened by it."
window.open('', '_self', '');
window.close();
"Scripts may close only the windows that were opened by it."
var customWindow = window.open('', '_blank', '');
    customWindow.close();
window.open("", '_self').window.close();
const closeWindow = () => {
 window.open(location.href, "_self", "");
 window.close()
}
window.open('your current page URL', '_self', '');
window.close();

JavaScript Error: Scripts may only close the windows that where opened by them

$("#closetab").click(function () {
    window.top.close();
});

Scripts may close only the windows that were opened by them

let cancelButton = document.querySelector("#cancel");
cancelButton.addEventListener("click", () => {
  console.log("close");
  Window.close();

  
});
context.callOnClose(this);

return {
  obm: {
    settings: {
      showPrefsPane: function () {
        Services.ww.openWindow(null, "resource://obm-connector/settings.html", '_blank', 'chrome,dialog,centerscreen', {})
      },

【令和版】window.close() でタブが閉じない時の解決法

if (window.history.length === 1) {
  // It is a browsing context whose session history contains only one Document.
}
if (window === window.top) {
  // It is a top-level browsing context
}
<button type="button" id="close">このボタンを押すとページが閉じます</button>

<script>
const closeBtn = document.getElementById('close');

closeBtn.addEventListener('click', function () {
  window.close();

  // `window.closed`を参照することでページが閉じられているかを確認できます。
  if (!window.closed) {
    this.textContent = '閉じるのに失敗しました';
  }
});
</script>
<p id="close">ブラウザの×ボタンを押して、このページを閉じてください。</p>

<script>
const placeholder = document.getElementById('close');

if (
  window.opener ||
  (
    window === window.top &&
    history.length <= 1
  )
) {
  const closeBtn = document.createElement('button');

  closeBtn.type = 'button';
  closeBtn.textContent = 'このボタンを押してページを閉じます';
  closeBtn.addEventListener('click', function () {
    window.close();
  });
  placeholder.replaceWith(closeBtn);
}
</script>

Window.close not working in Chrome (Javascript)

window.open('', '_self', ''); //bug fix
window.close();
<html>
<head>
<script>
function CloseWin()
{
	window.close();
}
</script>
</head>
<body>
<a onclick="javascript:CloseWin()">Close Window</a>
</body>
</html>

Previous PostNext Post

Related code examples