Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将域存储在本地存储中并在href中调用它_Javascript_Html - Fatal编程技术网

Javascript 将域存储在本地存储中并在href中调用它

Javascript 将域存储在本地存储中并在href中调用它,javascript,html,Javascript,Html,我允许用户在本地存储中存储域(例如)。我将域从本地存储中拉出的方法如下: <script type="text/javascript"> domain = localStorage['domain']; function DOMAIN(dive) { window.location=domain+dive; } </script> <a href="javascript:DOMAIN('/');">CLICK HERE</a>

我允许用户在本地存储中存储域(例如)。我将域从本地存储中拉出的方法如下:

<script type="text/javascript">
  domain = localStorage['domain'];
  function DOMAIN(dive) {
    window.location=domain+dive;
  }
</script>
<a href="javascript:DOMAIN('/');">CLICK HERE</a>

domain=localStorage['domain'];
功能域(潜水){
window.location=domain+dive;
}
我可以这样打开它:

<script type="text/javascript">
  domain = localStorage['domain'];
  function DOMAIN(dive) {
    window.location=domain+dive;
  }
</script>
<a href="javascript:DOMAIN('/');">CLICK HERE</a>


但我似乎无法让它允许在新选项卡(ChromeV13)中打开。我快发疯了,有什么建议吗?

试试这个:

<a href="#" onClick="javascript:DOMAIN('/');" target="_blank">CLICK HERE</a>

让我们看看这是否适合您:

<a href="javascript:window.open(DOMAIN('/'));void(0);">CLICK HERE</a>

好吧,我想出来了,但有点烦躁不安。制作一个虚拟html文档,比如说
/html/home.html
。在虚拟文档中调用js函数:

<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  <title>Ripping Status</title>
  <script type="text/javascript">
    domain = localStorage['domain'] || '';
    function init() {
      window.location=domain+'/';
      document.getElementById( 'box' );             
    };
  </script>
</head>
<body onload="init();">
  <div id="box"></div>
</body>
</html>

它允许右键单击>打开新选项卡、窗口等,正如您所期望的那样

你试过锚定标签的目标属性了吗?刚刚打开了一个新标签中的窗口。我以前见过,但我似乎无法在新选项卡中打开js链接。浏览器在新选项卡上的行为不同,您可以调整浏览器以在新选项卡中而不是在新窗口中打开新链接,也可以尝试_newtab.Asad,这只是在新选项卡中打开同一窗口,并在同一选项卡中启动目标域,与Aziz的答复相同。但它确实有右键单击“打开新选项卡”(与现有选项卡重复)。此外,用户不必调整整个浏览器中的设置,以使js href具有与href=”相同的行为htttp://stuff“,我希望如此。这是一个新的选项卡,其中包含:blank和用户域的目标选项卡。此外,无需右键单击即可打开“新建”选项卡。