japangreg
10-15-2002, 03:50 PM
Hey, everyone. I had visited the board before and posted a question about a script, which was answered thanks to the help of JSB and Owl (thanks again, guys) I have another problem with the same script.
I have written a basic image-handler page using JS to extract the image name and attributes from the URL called. For example, if I create a link anywhere on my site to "picture_pop.html?image1.gif" then the image handler page appears with "image1.gif" in a cell of a table. This was working perfectly in both IE and Netscape. Below is the code for the first version (that works in both IE and NS):
<!-- JavaScript to take image name from URL and add it to a SRC tag -->
<script>
try1 = window.location.toString();
//converts current URL to a string. Uncomment the alert below to see the value for try1
//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. Uncomment the alert below to see the value for result
//alert(result);
document.writeln('<img src="http://www.japangreg.com/images/' + result + '">');
//write passed image name to img src
</script>
What I had then tried to do was to expand the functionality to include other parameters one can enter into an <img> tag (tested and functional in IE with width, height, alt, and style). This worked perfectly (thanks to Owl's code :)) in IE, but when I test it with NS, the background becomes black. All of the parameters are passed correctly (with the exception of the style properties; dang DOM) Does anyone have any idea why the background is changing color? The code is below:
<!-- JavaScript to take image name from URL and add it to a SRC tag -->
<script>
try1 = window.location.toString();
//converts current URL to a string. Uncomment the alert below to see the value for try1
//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. Uncomment the alert below to see the value for result
//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
additions2 = unescape(additions);
s = additions2.split('&').join(' ');
//alert(s);
complete = tag_opener + s + ">"
}else{
complete = tag_opener + "'>"
}
document.writeln(complete);
//write passed image name to img src
</script>
Any help is greatly appreciated!
Thanks!
japangreg
I have written a basic image-handler page using JS to extract the image name and attributes from the URL called. For example, if I create a link anywhere on my site to "picture_pop.html?image1.gif" then the image handler page appears with "image1.gif" in a cell of a table. This was working perfectly in both IE and Netscape. Below is the code for the first version (that works in both IE and NS):
<!-- JavaScript to take image name from URL and add it to a SRC tag -->
<script>
try1 = window.location.toString();
//converts current URL to a string. Uncomment the alert below to see the value for try1
//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. Uncomment the alert below to see the value for result
//alert(result);
document.writeln('<img src="http://www.japangreg.com/images/' + result + '">');
//write passed image name to img src
</script>
What I had then tried to do was to expand the functionality to include other parameters one can enter into an <img> tag (tested and functional in IE with width, height, alt, and style). This worked perfectly (thanks to Owl's code :)) in IE, but when I test it with NS, the background becomes black. All of the parameters are passed correctly (with the exception of the style properties; dang DOM) Does anyone have any idea why the background is changing color? The code is below:
<!-- JavaScript to take image name from URL and add it to a SRC tag -->
<script>
try1 = window.location.toString();
//converts current URL to a string. Uncomment the alert below to see the value for try1
//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. Uncomment the alert below to see the value for result
//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
additions2 = unescape(additions);
s = additions2.split('&').join(' ');
//alert(s);
complete = tag_opener + s + ">"
}else{
complete = tag_opener + "'>"
}
document.writeln(complete);
//write passed image name to img src
</script>
Any help is greatly appreciated!
Thanks!
japangreg