I have a form that takes user inputted url and replaces an old url with a new one. The url the user will input is in this format: https://oldproxy.server.url.edu/login?url=https://destinationurl.com. OR http://oldproxy.server.url.edu/login?url=https://destinationurl.com
My script successfully finds all instances when the user starts with http, but if they start with https it fails. How can I include to check for http or https?
<!DOCTYPE html>
<head></head>
<body>
<script language="javascript">
<!--//--><![CDATA[// ><!--
function makeLink() {
var oin = document.frm.intext;
var oout = document.frm.outtext;
var intxt = oin.value;
if (intxt.length == 0) {
oin.focus();
alert("No URL entered!");
} else {
//no
var prep = "https://newproxy.server.url.edu";
//no
var rc = intxt.indexOf('.newproxy.server.url.edu/')
var rd = intxt.indexOf('.newproxy.server.url.edu')
var wellFormedHttp = intxt.indexOf('http://')
var wellFormedHttps = intxt.indexOf('https://')
if (wellFormedHttp == '0' || wellFormedHttps == '0') {
//alert("Matched http://"+wellFormed);
//}
if (rc == -1) {
if (rd == -1) {
intxt = intxt.replace(/http:\/\/oldproxy.server.url.edu/g, "")
oout.value = prep + intxt;
oout.focus();
oout.select();
} else {
alert("dont need to replace");
intxt = intxt.replace(/.newproxy.server.url.edu/g, "")
oout.value = prep + intxt;
oin.focus();
oin.select();
}
} else {
alert("duplicate");
oout.value = "";
oin.focus();
oin.select();
}
} else {
alert("The URL source URL doesn't start with http:// or https:// or contains multiple entries, please enter a valid URL like https://someaddress.com");
oout.value = "";
oin.focus();
oin.select();
}
}
}
//--><!]]>
</script>
<form name="frm" id="frm">
<h3>1. Copy and paste your source URL here:</h3>
<p><textarea aria-label="Source URL" cols="60" name="intext" rows="5"></textarea><br />
</p>
<h3>2. Click this:</h3>
<p><input onclick="makeLink();" type="button" class="btn" value="CONVERT LINK" /><br />
</p>
<h3>3. Copy, use, and share the resulting link</h3>
<p><textarea aria-label="Resulting Link" cols="60" name="outtext" rows="5" id="myInput"></textarea></p>
</form>
</body>
</html>
https://oldproxy.server.url.edu/login?url=https://destinationurl.com-expected output is:https or http://newproxyserver.url.edu/login?url=whatever they inputted above(destinationurl.com)