Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.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 如何创建一个链接,当单击该链接时,它会将您带到一个页面,并打开一个指向另一个url的新选项卡?_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何创建一个链接,当单击该链接时,它会将您带到一个页面,并打开一个指向另一个url的新选项卡?

Javascript 如何创建一个链接,当单击该链接时,它会将您带到一个页面,并打开一个指向另一个url的新选项卡?,javascript,jquery,html,Javascript,Jquery,Html,我希望有一个链接,单击该链接可执行两个操作: 将浏览器的当前选项卡重定向到url A 打开一个新选项卡,将浏览器指向url B 我该怎么做?这个有HTML吗?我应该使用javascript吗?您需要使用javascript来实现这一点,大致如下: $('#foo').click(function(e) { e.preventDefault(); // stop the normal link behaviour so you can open a new window windo

我希望有一个链接,单击该链接可执行两个操作:

  • 将浏览器的当前选项卡重定向到url A
  • 打开一个新选项卡,将浏览器指向url B

  • 我该怎么做?这个有HTML吗?我应该使用javascript吗?

    您需要使用javascript来实现这一点,大致如下:

    $('#foo').click(function(e) {
        e.preventDefault(); // stop the normal link behaviour so you can open a new window
        window.open('http://foo.com/new-page'); // open new tab
        window.location.assign($(this).prop('href')); // go to new page in current tab
    });
    

    您需要使用javascript来实现这一点,大致如下:

    $('#foo').click(function(e) {
        e.preventDefault(); // stop the normal link behaviour so you can open a new window
        window.open('http://foo.com/new-page'); // open new tab
        window.location.assign($(this).prop('href')); // go to new page in current tab
    });
    
    没有jQuery

    <a href='#' onclick="f();return false;">link</a> // add onclick event
    
    <script>
    function f(){
    document.location='/a.html'; // open in same tab
    window.open('/b.html','_blank'); // open new tab
    }
    </script>
    
    //添加onclick事件
    函数f(){
    document.location='/a.html';//在同一选项卡中打开
    window.open('/b.html','u blank');//打开新选项卡
    }
    
    不带jQuery

    <a href='#' onclick="f();return false;">link</a> // add onclick event
    
    <script>
    function f(){
    document.location='/a.html'; // open in same tab
    window.open('/b.html','_blank'); // open new tab
    }
    </script>
    
    //添加onclick事件
    函数f(){
    document.location='/a.html';//在同一选项卡中打开
    window.open('/b.html','u blank');//打开新选项卡
    }