"Error: mozilla is not defined"

P

Peter

Hello,

First of all, sorry for all the code. I don't know how to explain my
problem without it.

I have a javascript function which can build a webpage dynamically. A
striped down version of the function
looks like this:

BEGIN CODE

function buildPage(browser,contentPage) {
//contentPage is the page to load in the iframe

var header = "<html><head><title>SomeTitle</title>";

// different browsers will get different .css-files. the argument
// "browser" is used to select which
// .css-file to use (mozilla, opera or IE)
header += "<link rel=\"stylesheet\" type=\"text/css\"
href=\"system/" + "/" + browser + "/" + "styles.css\">";
header += "</head><body>";

var body = "<table class=\"container\"><tr><td>";

// here comes the line which generates an error.
// The pages which is build with the buildPage function
// contains a call to the buildPage function which is executed
// in the case a user clicks the link "Library".
// This is to build the page again, but with a different page
// loaded in the iframe (se below)
body += "<div class=\"navigation\" id=\"links\"><a href=\"#\"
onClick=\"buildPage(" + browser + "," + "'default'" + "," +
"'system/pages/library.html');\">Library</a></div>";


// here's the iframe which uses the contentPage argument
body += "<iframe class=\"content\" src=\"" + contentPage +
"\"></iframe>";
body += "</td></tr></table>";

var footer = "</body></html>";

var page = header + body + footer;

document.write(page);
}

END CODE

The HTML-page which calls this one looks like this:

BEGIN CODE

<html>
<head>
<title></title>
<script src="system/js/buildPage.js"></script>
</head>
<body>
<script>
var browser = navigator.appName;

if (browser == "Opera") {
browser = "opera";
} else if (browser == "Microsoft Internet Explorer") { browser = "explorer";
} else browser = "mozilla";

buildPage(browser,"system/pages/frontpage.html");
</script>
</body>
</html>

END CODE

And the page library.html looks like this:

BEGIN CODE

<html>
<head>
<script src="../../system/db/library.js"></script>
<script src="../../system/js/build.js"></script>
<script src="../../system/js/showHideLayer.js"></script>
</head>
<body>
<script>buildList("mozilla","article");</script>
</body>
</html>

END CODE

My problem is that when I press the link "Library" I get this error
from mozillas javascript console:

"Error: mozilla is not defined"

It does find out that the argument "browser" is mozilla (when using
this browser). Now all it has to do is use this string to collect the
correct .css-file.

What exectly is meant with the above error and how do I make the
browser used the string "mozilla" which it found from the "browser"
argument?

Thanks
/Peter
 
P

Peter

The problem is that when you wrote the code to the new page,
you wrote the string value of the variable browser, the string
mozilla (if you set browser="mozilla" and then do alert(browser),
it shows the string value, mozilla, not "mozilla"). Add the
double quotes the the new page it is writing.

That seems to be it. It works fine in Opera 7.03 and IE 6 on Win XP,
but Mozilla 1.4 appears to be loading the new page, but then ends up
loading the old page again.

Also in Opera and IE, after having clicked the link, no other links
work anymore. IE gives the error "an object was expected" (This is a
translation. I don't know the exact words used in the english IE).

Any suggestions as to what is wrong?

Thanks
/Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top