PDA

View Full Version : IE vs. Netscape; script fails after mod


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

Roy Sinclair
10-15-2002, 09:12 PM
I would guess that the problem is caused by these lines right here:


complete = tag_opener + s + ">"
}else{
complete = tag_opener + "'>"


You will see that I've highlighted a closing quote on one side of your else clause that simply isn't closed on the other side. This looks like anothe case of IE incorrectly forgiving a syntax error and making you look for a problem that really doesn't exist in the browsers that are having trouble with the code.

japangreg
10-15-2002, 09:52 PM
Hey, Roy Sinclair. Thanks for the reply.

You’re right; that quotation mark shouldn’t be there (because I do close it when I define the image name as tag_opener) However, correcting that did not solve my problem. NS still turns black in the background. Any other thoughts as to what might be causing this?

Thanks again!
japangreg

japangreg
10-16-2002, 02:18 PM
~~~~~~

Roy Sinclair
10-16-2002, 08:48 PM
Since you didn't post any of the rest of your page, I put it into a simple page and tested it and it works just fine without changing background colors or anything else. What's going on must be an interaction with some other part of your page.

japangreg
10-16-2002, 09:51 PM
Hmmm.

Very strange.

I just did the same (removed all coding except for the JS) and it does seem to function in NS. This is very odd, as the only thing I altered between the earlier version (that worked in NS) and the last version (that did not) is the JavaScript, not any of the other coding that appears to be causing the problem.

Well, thanks for the help, Roy Sinclair. It appears my JS isn't the problem, so I'll go look into my HTML and see what I could be screwing up this time. :)

Thanks again!
japangreg


Apparently, the problem is being caused by a CSS line for the body background. Although it functioned well with the earlier script, the new, more powerful one seems to be, for lack of a better term, 'wacking it out'.