Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Query String with HTML
03-19-2009, 03:48 PM (This post was last modified: 03-19-2009 03:50 PM by shazin.)
Post: #1
Information Query String with HTML
We all know that we can use a query string with most of the server side scripts to dynamically generate pages based on conditions passed through those query string. You can do the same with HTML without the need of a server side script. The below example considers a html page dynamically displays an image based on the passed image query string.


HTML and JavaScript Code
<html>
<head><title>Query String Test</title></head>
<body onload="onload()">
<script language="javascript">
function onload(){
var image = document.getElementById('image');
var url = '' + window.location;
var query = url.substring(url.indexOf('?')+1);
var pair = query.split('=');
image.src = pair[1];
}
</script>
<image id='image'/>
</body>
</html>

Save the html file in a directory and put the images you want to load in the same directory.

Now type in the address bar of the browser file:///<Path to HTML>?image=<image file name with extension>

You can load any image by just changing the image= query.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


Contact Us | Coder Passion | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication | Site Map