Solved

Remove Protocol if at start of string?

Posted on 2016-11-25
3
38 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 28

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I split a variable to newline 2 44
Where is this content coming from? 4 40
Javascript question 8 44
Javascript function 3 20
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-…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

734 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