1
roojo
Dinamic header Image from parameter in URL
  • 2006/8/28 21:55

  • roojo

  • Just popping in

  • Posts: 3

  • Since: 2005/5/7 1


Hello, i don't know if this will be of any use to someone else, but i had a friend who wanted to have different image headers for his news topics and so poking around the net i found a javascrit to get the value of a param and used it for it.

here is the code.

function getURLParam(strParamName){
  var 
strReturn "";
  var 
strHref window.location.href;
  if ( 
strHref.indexOf("?") > -){
    var 
strQueryString =
strHref.substr(strHref.indexOf("?")).toLowerCase();
    var 
aQueryString strQueryString.split("&");
    for ( var 
iParam 0iParam aQueryString.lengthiParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName "=") > -){
        var 
aParam aQueryString[iParam].split("=");
        
strReturn aParam[1];
        break;
      }
    }
  }
  return 
strReturn;
}

var 
topic getURLParam("storytopic");

switch(
topic)
   {
      case 
"1":
                        
document.writeln('<img src="image1.jpg">');
         break;
      case 
"2":
                        
document.writeln('<img src="image2.jpg">');
         break;
      case 
"3":
                        
document.writeln('<img src="image3.jpg">');
         break;
      default:
                        
document.writeln('<img src="default.jpg">');
         break;
   }


getURLParam("storytopic");

returns the value of storytopic wich according to the switch display the image requiered or a default image if theres no value.

i think this is usefull for theme presonalitation, anyway there you have it...

All the best.

Login

Who's Online

136 user(s) are online (51 user(s) are browsing Support Forums)


Members: 0


Guests: 136


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits