javascript window.open without http://

前端 未结 5 1873
独厮守ぢ
独厮守ぢ 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 05:09

    I made small changes function form answered by iMoses which worked for me.

    Check for both https OR http protocol

    if (!url.match(/^http?:\/\//i) || !url.match(/^https?:\/\//i)) {
            url = 'http://' + url;
        }
    

    Hope it make more accurate for other situation !

提交回复
热议问题