How to add target=“_blank” to JavaScript [removed]?

后端 未结 4 759
渐次进展
渐次进展 2020-11-28 03:05

The following sets the target to _blank:

if (key == \"smk\") {
    window.location = \"http://www.smkproduction.eu5.org\";
    target = \"_blank         


        
相关标签:
4条回答
  • 2020-11-28 03:31

    I have created a function that allows me to obtain this feature:

    function redirect_blank(url) {
      var a = document.createElement('a');
      a.target="_blank";
      a.href=url;
      a.click();
    }
    
    0 讨论(0)
  • 2020-11-28 03:37

        var linkGo = function(item) {
          $(item).on('click', function() {
            var _$this = $(this);
            var _urlBlank = _$this.attr("data-link");
            var _urlTemp = _$this.attr("data-url");
            if (_urlBlank === "_blank") {
              window.open(_urlTemp, '_blank');
            } else {
              // cross-origin
              location.href = _urlTemp;
            }
          });
        };
    
        linkGo(".button__main[data-link]");
    .button{cursor:pointer;}
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    
    <span class="button button__main" data-link="" data-url="https://stackoverflow.com/">go stackoverflow</span>

    0 讨论(0)
  • 2020-11-28 03:41

    Just use in your if (key=="smk")

    if (key=="smk") { window.open('http://www.smkproduction.eu5.org','_blank'); }
    
    0 讨论(0)
  • 2020-11-28 03:51

    window.location sets the URL of your current window. To open a new window, you need to use window.open. This should work:

    function ToKey(){
        var key = document.tokey.key.value.toLowerCase();
        if (key == "smk") {
            window.open('http://www.smkproduction.eu5.org', '_blank');
        } else {
            alert("Kodi nuk është valid!");
        }
    }
    
    0 讨论(0)
提交回复
热议问题