Javascript - Open a given URL in a new tab by clicking a button

前端 未结 13 434
一生所求
一生所求 2020-12-04 13:35

I would like to have a button that redirects to a given URL and opens in a new tab. How can this be done?

相关标签:
13条回答
  • 2020-12-04 14:31

    You can't. This behaviour is only available for plugins and can only be configured by the user.

    0 讨论(0)
  • 2020-12-04 14:33

    Use this:

    <input type="button" value="button name" onclick="window.open('http://www.website.com/page')" />
    

    Worked for me and it will open an actual new 'popup' window rather than a new full browser or tab. You can also add variables to it to stop it from showing specific browser traits as follows:

    onclick="window.open(this.href,'popUpWindow','height=400,width=600,left=10,top=10,,scrollbars=yes,menubar=no'); return false;"
    
    0 讨论(0)
  • 2020-12-04 14:35

    Adding target="_blank" should do it:

    <a id="myLink" href="www.google.com" target="_blank">google</a>
    
    0 讨论(0)
  • 2020-12-04 14:37
    <BUTTON NAME='my_button' VALUE=sequence_no TYPE='SUBMIT' style="background-color:transparent ; border:none; color:blue;" onclick="this.form.target='_blank';return true;"><u>open new page</u></BUTTON>
    

    This button will look like a URL and can be opened in a new tab.

    0 讨论(0)
  • 2020-12-04 14:38

    try this

    <a id="link" href="www.gmail.com" target="_blank" >gmail</a>
    
    0 讨论(0)
  • 2020-12-04 14:40

    USE this code

    function openBackWindow(url,popName){
            var popupWindow = window.open(url,popName,'scrollbars=1,height=650,width=1050');
              if($.browser.msie){
                popupWindow.blur();
                window.focus();
            }else{
               blurPopunder();
            }
          };
    
        function blurPopunder() {
                var winBlankPopup = window.open("about:blank");
                if (winBlankPopup) {
                    winBlankPopup.focus();
                    winBlankPopup.close()
                }
        };
    

    IT works fine in Mozilla,IE and chrome on and less than 22 version; but doesn't work in Opera and Safari.

    0 讨论(0)
提交回复
热议问题