Forum Moderators: open
What I want to do is take a url like this:
www.randomdomain.com/?keyword=My%20Random%20Domain
And in the HTML for this site if I put in some reference like &keyword& the keyword "My Random Domain" will be inserted as text onto my website.
I imagine there are quite a few ways this can be done but I figure javascript is the best.
Any suggestions would be greatly appreciated.
Thanks!
Take a look at the script developed in this thread:
[webmasterworld.com...]
It should help you to do exactly what you are asking.
HTH
To get information from search parameters, one good way is to parse the search string, and create an object with the keys as property names, and the values as ... values.
[pre]
function parseSearch()
{
var U = unescape ;
var pObj = new Object;
var pArr = window.location.search.substring(1).split(/[&=]/);
for(var k=0;k<pArr.length;k+=2)
pObj[U(pArr[k])] = U(pArr[k+1]);
return pObj;
}[blue]// get object by parsing string[/blue]
var params = parseSearch();
[blue]// get the 'one' value[/blue]
alert(params.one)
[blue]// or enumerate to get all values[/blue]
ops = '';
for(var p in params)
ops += p+': '+params[p] + '\n'
alert(ops)
[/pre]
---------------------------------------------------------------
While on the subject of getting the filename, I thought that the solution offered in the thread quoted comes up a bit short, since it offers different versions for Windows and Unix. Many people will be writing on Windows and posting to Unix.
I reckon regular expressions should be brought into play. Here's my version:
docName = window.location.split(/[\/\\]/).pop().split('.')[0]
or, for non-popping browsers:
docName = window.location.replace(/.*[\/\\]¦\..*$/g,'')