Sign in to follow this  

Beginner JavaScript Question

This topic is 3579 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm pretty new to javascript and I've got a question about how it handles reloads. I have an onload function call set up in a body tag of an HTML file and it calls the function fine when the page is loaded but when you hit reload, it's not recalled. For some reason it's on a problem in Firefox and in IE it seems to be working just fine. Any help is appreciated.

Share this post


Link to post
Share on other sites
Here's my code:


<html>
<head>
<script language="JavaScript">

function getTitle(filename)
{
var nameArray = filename.split("/");
var index = nameArray.length - 2;
if(nameArray[index].indexOf(".") > -1)
{
return "Ethereal Divine";
}
else
{
return nameArray[index];
}
}

function updateTitle()
{
//document.write("<table border width=100%>");
//document.write("<tr width=100%>");
//document.write("<td width=10%><img src=\"darthvader.jpg\" width=100%></td>");
//document.write("<td width=80%><center><font color=\"red\"><h1>" + getTitle(parent.frames[2].location.href) + "</h1></font></center></td>");
//document.write("<td width=10%><img src=\"Wolf.jpg\" width=100%></td>");
//document.write("</tr></table>");
document.write("<center><font color=\"red\"><h1>" + getTitle(parent.frames[2].location.href) + "</h1></font></center>");
}
</script>
</head>
<script>
</script>
<body bgcolor="black">
<script language="JavaScript">
updateTitle()
</script>
</body>
</html>



I've moved the call out of onload but it still produces strange results - it seems to work on the first run in Firefox and it works fine in IE but refresh kills it in Firefox (title is not rendered).

Also, if I take out the document.write comment and put in the others, I'm attempting to create a table, which IE blows up horizontally, violating all the td constraints which I would expect it should be forced to follow since they're specifically stated in the table declaration.

The page is referenced within a frame from my index.html file, and parent.frames[2] represents the main body document.

Any help is appreciated.

Share this post


Link to post
Share on other sites

This topic is 3579 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this