Hello Webdevelopers,
this thread is a continuation of the “Need Help to understand browsers behaviors”. I am creating a new thread because I found old title not very clear.
My objective is to call from an js source file the algorithm to form an string because it is pretty complex and We want to support it on a javascript file instead of support the string that will be printed in the newWindow. Let’s first start with the simplest code, the one that is used to call the popup window:
[code=html]
<html>
<head>
<script language=”JavaScript”>
function displayPopupWin() {
newwin = window.open();
newHtml = “<html> n” +
“<body> n” +
“<script language=’javascript’> n” +
“t document.write(‘Hello’); n” +
“</scr” + “ipt> n” +
“</body> n” +
“</html> n”;
newwin.document.open();
newwin.document.write(newHtml);
newwin.document.close();
}
</script>
</head>
<body>
<a href=”#” onClick=”javascript:displayPopupWin()”>Click here to display Popup Window</a>
</body>
</html>
The code above creates a web page with a link to call the displayPopupWin() function, that generates the new Window.
The source code on IE6.2 is:
[code=html]
<html>
<body>
<script language=’javascript’>
document.write(‘Hello’);
</script>
</body>
</html>
and in FireFox 1,5 is:
[code=html]
<html>
<body>
<script language=’javascript’>
document.write(‘Hello’);
</script>
</body>
</html>
Hello **********
**********Notice the extra Hello at the end of the source code.
It works perfect in both browser, but, by looking on the source code, We are only printing a hardcoded string.
Now, let’s try to write the content of the page from the JS source file:
The webpage code is:
[code=html]
<html>
<head>
<script language=”JavaScript” src=”myJSSource.js”></script>
<script language=”JavaScript”>
function displayPopupWin() {
newwin = window.open();
newHtml = “<html> n” +
“<body> n” +
“<script language=’javascript’ src=’myJSSource.js’></scr” + “ipt> n” +
“<script language=’javascript’> n” +
“t document.write(myComplexContent()); n” +
“</scr” + “ipt> n” +
“</body> n” +
“</html> n”;
newwin.document.open();
newwin.document.write(newHtml);
newwin.document.close();
}
</script>
</head>
<body>
<a href=”#” onClick=”javascript:displayPopupWin()”>Click here to display Popup Window</a>
</body>
</html>
and the myJSSource.js code is:
[CODE]
function myComplexContent() {
return “Hello”;
}
The result is:
IE6.2:
The “Display a notification about every script error” returns: “Error: Object expected” in the line that contains myComplexContent() function. After that, if I refresh the generated page everything works fine, and the source code [B]after refreshing
[CODE]
<html>
<body>
<script language=’javascript’ src=’myJSSource.js’></script>
<script language=’javascript’>
document.write(myComplexContent());
</script>
</body>
</html>
FireFox 1.5:
The browser display the correct result (it prints the value returning for the myComplexContent() function on the screen) but it looks like it is not finishing to load the webpage, and it doesn’t display code in the view source window.
Ok, let me know if the explanation of the problem is clear, any help and comment is welcome, also comments about my writting are welcome, English is not my first language and I want to improve it.
Regards,
Jaime