Hello Everyone,
I am new to this forum and also new to JavaScript programming. Please forgive my ignorance upfront. (I truly mean it…I am totally green to javascript)
I am trying to create bookmarklets for both IE & FireFox that allow me to create certain test urls for a staging site.
What I need to do is be able to have the script add to the end of the live url string ‘?test=true’.
I have site that if I add the paratmeters “?test=true” to the end of the page, (i.e. [url]www.mysite.com?test=true[url]www.mysite.com
So the first thing that this bookmarklet needs to do is take the URL of the page that I am browsing right now and add to it at the very end “?test=true”
Of course, this poses a problem in that if the URL that I am browsing right now already has the hook (?) in it, I cannot add another one and therefore need the bookmarklet to detect if any (?) is in the URL and if so place “&test=true” instead of “?test=true” at the end of the URL.
Here is the code that I am working with:
For IE:
[CODE]<html>
<head>
<script language=”JavaScript” TYPE=”text/javascript” >
function runme() {
var proxyHost, fullUrl, endIdx, idx, prefix, url, hostName, flippedHost;
proxyHost = ‘mysite.com’;
fullUrl = prompt(‘URL to Test:’,”);
endIdx = fullUrl.indexOf(‘?’);
if (endIdx < 0) endIdx = fullUrl.length;
idx = fullUrl.indexOf(‘//’);
if (idx==0 || idx==5 || idx==6) {
idx += 2;
}
else {
idx = 0;
}
if (fullUrl.indexOf(‘https:’) >= 0) {
prefix = ‘https://’;
}
else {
prefix = ‘http://’;
}
url = fullUrl.substring(idx,fullUrl.length);
idx = url.indexOf(‘/’);
if (idx == -1) idx = url.length;
hostName = url.substring(0,idx);
flippedHost = ”;
for (i = hostName.length-1; i >= 0; i–) flippedHost += hostName.charAt(i) == ‘.’ ? ‘/’ : hostName.charAt(i);
document.write(‘<a href = “‘ + prefix + proxyHost + ‘/’ + flippedHost + ‘/u1=$(vid)/%5e’ + url.substring(idx,url.length)+ ‘”>’+prefix + proxyHost + ‘/’ + flippedHost + ‘/u1=$(vid)/%5e’ + url.substring(idx,url.length)+ ‘</a><br>’);
document.close();
}
</script>
</head>
<body onload = “runme()”>
</body>
</html>
For FireFox
[CODE]javascript: var proxyHost, fullUrl, endIdx, idx, prefix, url, hostName, flippedHost; proxyHost = ‘mysite.com’; fullUrl = prompt(‘URL to proxy:’,”); endIdx = fullUrl.indexOf(‘?’); if (endIdx < 0) endIdx = fullUrl.length; idx = fullUrl.indexOf(‘//’); if (idx==0 || idx==5 || idx==6) { idx += 2; } else { idx = 0; } if (fullUrl.indexOf(‘https:’) >= 0) {prefix = ‘https://’; }else {prefix = ‘http://’; } url = fullUrl.substring(idx,fullUrl.length); idx = url.indexOf(‘/’); if (idx == -1) idx = url.length; hostName = url.substring(0,idx); flippedHost = ”; for (i = hostName.length-1; i >= 0; i–) flippedHost += hostName.charAt(i) == ‘.’ ? ‘/’ : hostName.charAt(i); document.write(‘<a href = “‘ + prefix + proxyHost + ‘/’ + flippedHost + ‘/u1=$(vid)/%255e’ + url.substring(idx,url.length)+ ‘”>’+prefix + proxyHost + ‘/’ + flippedHost + ‘/u1=$(vid)/%255e’ + url.substring(idx,url.length)+ ‘</a><br>’);document.close();
Thank you all very much for your help! ?