URL parameters

I have used URL parameters a few times for survey reporting. Elements which require custom markup are often more easily defined as separate webpages, these can then be embedded as iframes and tested thoroughly on their own.

Example: Custom image on webpage

We use two  URL parameters to form the source of a custom image on a webpage.
www.exampleurl.com?textvar=1&anothertextvar=ext  

A simple javascript in the header makes parsing of variables possible:
<!doctype html>  
 <html class="no-js" lang="en">  
 <head>  
 <meta charset="utf-8" />  
 <script>  
 function gup( name )  
 {  
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
  var regexS = "[\\?&]"+name+"=([^&#]*)";  
  var regex = new RegExp( regexS );  
  var results = regex.exec( window.location.href );  
  if( results == null )  
   return "";  
  else  
   return results[1];  
 }  
 </script>  
 </head>  
 <body>  
 <img alt="" hspace="0" id="example" vspace="0" width="800px" />  
 </body>  
 <script>  
 var imgSrc ="URL/Prefix"+gup('textvar')+"_"+gup('anothertextvar')+".png";  
 document.getElementById("example).src = imgSrc;  
 </script>  
 </html>  

Embed in iframe

It is rather straight forward to embed the graphics in an iframe and using the id tag.

<iframe frameborder="0" height="1050px" id="test" scrolling="no" width="100%"></iframe>  


Just add a script by the end of the page or following the iframe tag set.

<script>  
 var textvar=1;  
 var anothertextvar="ext";  
 document.getElementById("test").src = "URL/Example.html?textvar="+textvar+"&anothertextvar="+anothertextvar;  
 </script>  


Comments

Popular Posts