japangreg
09-26-2002, 02:38 PM
Hey, everyone.
I am working on a script in an HTML file to open any image document on the server by adding some information to the URL I use to call the page. So, when I write a link as:
<a href="picture_pop.html?image1.jpg">
picture_pop.html opens, executes my script and displays image1.jpg in it's proper place (in a cell in a table)
I have this working. What I'm trying to do now is add arguments to the end of the URL to alter height, width, style, ect. So my link now appears as follows:
<a href="picture_pop.html?image1.jpgheight=200width=100">
I can get the name of the image, the height and width into variables. So now I have the following:
image_name = "image1.jpg";
width = "width=100";
height = "height="200";
out_put = "<img src='/images/" + image_name + width + height + "'>";
document.writeln(out_put);
My problem occurs because I do not have any spaces in the variables. So what gets printed to my HTML file appears as:
<img src="/images/image1.jpgwidth=100height=200">
I've tried adding a space to the variables and then combining them, but I get the %20 character where the space should be. I've tried unescaping the "out_put" variable, but that still generates the %20.
Any help would be appreciated. The entire code section follows (variable names may be changed from above):
try1 = window.location.toString();
//converts current URL to a string
//alert(try1);
try2 = try1.indexOf("?")+1;
//finds image name delineator (?) position, begins substring on next character
result = try1.substring(try2);
//sets result equal to passed image name.
//alert(result);
format_seperator = result.indexOf(".")+4;
//finds the period after the file name, sets seperator three characters after it to include file type
image_name = result.substring(0,format_seperator);
tag_opener = "<img src='http://www.japangreg.com/images/" + image_name;
//sets the first part of the img tag to include the file name: code below adds paramaters
additions = result.substring(format_seperator);
//checks to see if there is anything behind the image name
if (additions && additions != "l"){
//there is something, and it isn't the L left behind when the
page is opened without a file after the ?
alert(additions);
//code to check for each parameter here
width_start = additions.indexOf("width");
height_start = additions.indexOf("height");
if (width_start < height_start){
//width is specified before height
width = additions.subString(width_start,height_start);
alert(width);
height = additions.subString(height_start);
alert(height);
}else{
//height is specified before width
height = additions.subString(height_start,width_start);
alert(height);
width = additions.subString(width_start);
alert(width);
complete = tag_opener + width + height + "'>";
}else{
complete = tag_opener + "'>";
//there are no additions, just cap the
img src tag and write it out
}
document.write(complete);
//write passed image name to img src
I am working on a script in an HTML file to open any image document on the server by adding some information to the URL I use to call the page. So, when I write a link as:
<a href="picture_pop.html?image1.jpg">
picture_pop.html opens, executes my script and displays image1.jpg in it's proper place (in a cell in a table)
I have this working. What I'm trying to do now is add arguments to the end of the URL to alter height, width, style, ect. So my link now appears as follows:
<a href="picture_pop.html?image1.jpgheight=200width=100">
I can get the name of the image, the height and width into variables. So now I have the following:
image_name = "image1.jpg";
width = "width=100";
height = "height="200";
out_put = "<img src='/images/" + image_name + width + height + "'>";
document.writeln(out_put);
My problem occurs because I do not have any spaces in the variables. So what gets printed to my HTML file appears as:
<img src="/images/image1.jpgwidth=100height=200">
I've tried adding a space to the variables and then combining them, but I get the %20 character where the space should be. I've tried unescaping the "out_put" variable, but that still generates the %20.
Any help would be appreciated. The entire code section follows (variable names may be changed from above):
try1 = window.location.toString();
//converts current URL to a string
//alert(try1);
try2 = try1.indexOf("?")+1;
//finds image name delineator (?) position, begins substring on next character
result = try1.substring(try2);
//sets result equal to passed image name.
//alert(result);
format_seperator = result.indexOf(".")+4;
//finds the period after the file name, sets seperator three characters after it to include file type
image_name = result.substring(0,format_seperator);
tag_opener = "<img src='http://www.japangreg.com/images/" + image_name;
//sets the first part of the img tag to include the file name: code below adds paramaters
additions = result.substring(format_seperator);
//checks to see if there is anything behind the image name
if (additions && additions != "l"){
//there is something, and it isn't the L left behind when the
page is opened without a file after the ?
alert(additions);
//code to check for each parameter here
width_start = additions.indexOf("width");
height_start = additions.indexOf("height");
if (width_start < height_start){
//width is specified before height
width = additions.subString(width_start,height_start);
alert(width);
height = additions.subString(height_start);
alert(height);
}else{
//height is specified before width
height = additions.subString(height_start,width_start);
alert(height);
width = additions.subString(width_start);
alert(width);
complete = tag_opener + width + height + "'>";
}else{
complete = tag_opener + "'>";
//there are no additions, just cap the
img src tag and write it out
}
document.write(complete);
//write passed image name to img src