Forum Moderators: open
var overview = "Overview of title of page";
However, when I use this in my HTML, all the strings are loaded, except for the string that I want to use for my <TITLE>. This is the code that I use in my HTML to call the external js file, then try the document.write for the overview string:
...
<SCRIPT type="text/javascript" language="javascript" SRC="strings.js"></SCRIPT>
<TITLE><script language="javascript">document.write(overview)</script></TITLE>
</HEAD>
...
The title on the browser then prints out everything between <TITLE> and </TITLE>.
Is this a limitation for the title tage, or is the JavaScript file not loading quickly enough? All the document.write's in the body are working just fine.
Is this a limitation for the title tage, or is the JavaScript file not loading quickly enough?
I don't know the answer to that. You could try:
<script>document.write("<title>"+overview+"<\/title>")</script> Although it's probably simpler to:
<title>default text</title>
<script>
document.title = overview
</script> With the 2nd way, you have the opp to put something slightly useful in as a default, for SE, JS-disabled etc
<script>document.write("<title>"+overview+"<\/title>")</script>
This worked nicely, and leaves a default value, as you mentioned:
<title>default text</title>
<script>
document.title = overview
</script>
Still wondering why the JS doesn't load in time for the <TITLE> tag.