taking off the http or https off a javascript string

前端 未结 12 1582
面向向阳花
面向向阳花 2020-12-20 11:23

I have the following strings

http://example.com
https://example.com
http://www.example.com

how do i get rid of the http:// or

12条回答
  •  [愿得一人]
    2020-12-20 11:53

    Strip the protocol from a URL:

    var url = "https://site.com";
    var urlNoProto = url.split('/').slice(2).join('/');
    

    Works with any protocol, ftp, http, gopher, nntp, telnet, wais, file, prospero ... all those specified in RFC 1738 with the exception of those without a // in them (mailto, news).

提交回复
热议问题