Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remove Protocol if at start of string?

Posted on 2016-11-25
3
Medium Priority
?
58 Views
Last Modified: 2016-11-25
How do I remove the protocol if it is only at the start of a string? No jQuery please, only JavaScript!

Input Examples:
1) http//www.mysite.com/?url=http//www.mysite.com
2) https//www.mysite.com/?url=https//www.mysite.com
3) //www.mysite.com/?url=http//www.mysite.com
4) //www.mysite.com/?url=https//www.mysite.com

Output Examples:
1) //www.mysite.com/?url=http//www.mysite.com
2) //www.mysite.com/?url=https//www.mysite.com
3) //www.mysite.com/?url=http//www.mysite.com
4) //www.mysite.com/?url=https//www.mysite.com

Thanks!
0
Comment
Question by:894359
3 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 41902056
var removeHTTPProtocol = function(url) {
    return url.replace(/^https?:/,"")
}

Open in new window

0
 
LVL 35

Expert Comment

by:Pawan Kumar
ID: 41902058
var strRemoveProtocol = (YourString.Replace("https","")).Replace("http","")
0
 

Author Closing Comment

by:894359
ID: 41902060
Than you!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question