首页 > 解决方案 > 如何在新选项卡中打开链接而不在新选项卡中看到 URL?

问题描述

我一直在尝试很多事情来完成这项工作,但还没有。如何在新标签页中打开网站,但不显示正在使用的 URL?我从这个网站得到了这个想法。新标签 URL 显示为about:blank。但是,我无法让它工作。我是 Javascript 新手,所以放轻松!谢谢!!!

这是我尝试过的:

function NewTab() {
  window.open(
    "https://www.mywebsite.com", "_blank");
}

标签: javascriptgoogle-sites

解决方案


在浏览了网站之后,我能够找到打开一个新选项卡的 JS,“而不”向用户公开 URL:

var urlObj = new window.URL(window.location.href);
var url = "https://tam-shellshock.franklinformulas.com"

if (url) {
  var win;
  document.querySelector('a').onclick = function() {
    if (win) {
      win.focus();
    } else {
      win = window.open();
      win.document.body.style.margin = '0';
      win.document.body.style.height = '100vh';
      var iframe = win.document.createElement('iframe');
      iframe.style.border = 'none';
      iframe.style.width = '100%';
      iframe.style.height = '100%';
      iframe.style.margin = '0';
      iframe.src = url;
      win.document.body.appendChild(iframe);
    }
  };
}
<a>Press here</a>


推荐阅读