javascript window.open without http://

前端 未结 5 1838
独厮守ぢ
独厮守ぢ 2021-01-05 04:18

I have a small tool build with Delphi that collects url\'s from a file or from the clipboard, and than builds a file called test.htm with a content like this :



        
5条回答
  •  醉梦人生
    2021-01-05 04:51

    I think the best way would be to add "//" + url In this case - it isn't important, what protocol (http or https) you expect to receive as a result.

    url = url.match(/^https?:/) ? url : '//' + url;
    window.open(url, '_blank');
    

提交回复
热议问题