Hoping someone can help me with a bit of script..
Im looking to display the keyword(domain) on my lander via
ie my keywords maybe
amazon.com
amazon.co
www.amazon.com
ww.amazon.co
w.amazon.c
ww.amazon
etc.
So basically i just wanna return "amazon"
Heres what ive got...
<head>
<script>
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] || ''
);
}
</script>
</head>
<body>
<h1>Welcome to the <script>document.write(getURLParameter('keyword'))</script> quiz</h1>
</body>
This should help you out buddy
http://stackoverflow.com/questions/1...st-without-www
Actually it may not help, re-read thread after replying. Id look into splitting the domain with javascript at each fullstop. In php youd use "explode" not sure with js off top of my head.
Unsure what you're looking for to be honest, do you just want to take the URL from the address bar and display just the domain with the TLD and any sub domains?
If so this rudimentary solution should work for most domains, I haven't tested it out properly so use at your own discretion
<html>
<head>
<script>
function split(){
var url = window.location.href;
var sp = url.split(".");
if(sp[sp.length-2].length <= 2){
return sp[sp.length-3];
}
else{
return sp[sp.length-2];
}
}
</script>
</head>
<body>
<h1>Welcome to the <script>document.write(split())</script> quiz</h1>
</body>
</html>
Read it wrong, just realised you want to clean up a URL parameter,this should do the trick for most domains
<html>
<head>
<script>
function getURLParameter(name) {
var kw = decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] || '');
var sp = kw.split(".");
if(sp[sp.length-2].length <= 2){
return sp[sp.length-3];
}
else{
return sp[sp.length-2];
}
}
</script>
</head>
<body>
<h1>Welcome to the <script>document.write(getURLParameter('keyword'))</script> quiz</h1>
</body>
</html>
Nice! Edited title and moved to useful scripts :-)
thanks Craig, that worked perectly.