Solved

Remove Protocol if at start of string?

Posted on 2016-11-25
3
41 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 82

Accepted Solution

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

Open in new window

0
 
LVL 29

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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

624 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