简体   繁体   English

如何在新标签页中打开链接而不在新标签页中看到 URL?

[英]How to open a link in a new tab without seeing the URL in new tab?

I've been trying many things to make this work but nothing has yet.我一直在尝试很多事情来完成这项工作,但还没有。 How can I open a website in a new tab and have it not show the URL being used?如何在新选项卡中打开网站,但不显示正在使用的 URL? I got this idea from this website .我从这个网站得到了这个想法。 The new tabs URL shows up as about:blank .新标签 URL 显示为about:blank However, I've not been able to get it to work.但是,我无法让它发挥作用。 I'm new to Javascript so go easy on me!我是 Javascript 的新手,所以放轻松! Thanks!!!谢谢!!!

This is what I've tried:这是我尝试过的:

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

After digging through the website I was able to find the JS that opens a new tab "without" exposing the URL to the user:在浏览网站后,我找到了打开新标签页的 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM