I found the JavaScript to break up the queryString of a page and pull a variable from it. I needed to do this so that I could create a new link that would put the website into a facebook app I am trying. Basically, we upload pages to our server which generates a long value (k). So, the URL is always http://www.oursite.com/webhost/login.asp?k=12342342334 etc.
Here is what I have so far:
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
var SurveyKey = querySt("k");
var url = "http://apps.facebook.com/appname/k=" + SurveyKey;
window.location = url;
}
So, I have a var called “url” which should give the correct URL for what I need it to do (basically just sets the page in a facebook canvas). I seem to be lost on how to make create a link for this.
It needs to be a button that someone clicks and it just opens a new window with the var url. What am I missing here? I tried
document.write="<a href="url...
but I can’t reference that variable.
Why not use PHP for it instead of Javascript? If you extract the variable from the URL in PHP you can just make the link:
If you want to do it in javascript:
Something along those lines at least.