Jump to content

Problems with two scripts in <head>


Fmdpa

Recommended Posts

Here is the top section of one of my pages. Notice I have an embedded script and and external (linked) script.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title></title><link rel="Shortcut Icon" href="favicon.ico"><!--external stylesheet:--><link href="styles/style.css" rel='stylesheet' type="text/css"><script type="text/JavaScript">document.write("scripts/script1.js");function changeImage(id, src){  document.getElementById(id).src = src;}</script></head><body>...

When I link that first script in there, it does everthing it is supposed to do, but it bumps the alignment of everything downward about 25-50px. I could embed that script as well, but it just would be very inconvenient in the event of an edit to the script. Any help?

Link to comment
Share on other sites

You can't just write the path like that and hope it'll work - you have to either hard link it (using another script tag), or write out the entire script tag using JS. Your code will just print "scripts/script1.js" on the page.

Link to comment
Share on other sites

In other words, before or after your embedded script (not inside the script) place this pair of tags:<script type="text/javascript" src="scripts/script1.js"></script>and forget that document.write business. document.write solves a very narrow set of problems, and I see no evidence of any of them here.

Link to comment
Share on other sites

You can't just write the path like that and hope it'll work - you have to either hard link it (using another script tag), or write out the entire script tag using JS. Your code will just print "scripts/script1.js" on the page.
Actually the script does everything it is supposed to do, but it messes up the alignment of the images.
Link to comment
Share on other sites

Actually the script does everything it is supposed to do, but it messes up the alignment of the images.
That would be strange if it did. The way you have it with the document.write shouldn't work. I tested it just to verify, and it doesn't.Do like DD said and get rid of that document.write and place your script tags outside the embedded script. It should look like this:
<script type="text/javascript" src="scripts/script1.js"></script><script type="text/javascript">...</script>

Link to comment
Share on other sites

That would be strange if it did. The way you have it with the document.write shouldn't work. I tested it just to verify, and it doesn't.Do like DD said and get rid of that document.write and place your script tags outside the embedded script. It should look like this:
<script type="text/javascript" src="scripts/script1.js"></script><script type="text/javascript">...</script>

That is actually what I did, but it didn't work in IE or FF. I'll try it again just to make sure.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...