zc2
12-13-2007, 08:41 PM
I need help to workaround the following problem:
First, about the environment:
- The web pages automatically generated.
- Pages can be inserted to each other
- When a subpage to be inserted is being generated, it does not know will it be inserted or not.
- That because each subpage uses the <script src=...> tags to load the script it needs.
- in the external script files I'm trying to protect it from repeated execution checking (if(){}) the value of a variable which is created after in the script.
Everything worked fine until I tried to use the .prototype to declare the method of my objects.
In the Internet Explorer, I got "Object does not support this property or method", on the access to a prototype function, because the prototype of my object was deleted by itself after the second load of the external script.
Here is the code sample:
<HTML><BODY>
<!-- content of the outer page -->
<script language="javascript" src="test.js"></script>
<script>
var a = new A;
a.CustomFunc(1);
</script>
<!-- content of the inserted subpage -->
<script language="javascript" src="test.js"></script>
<script>
var b = new A;
b.CustomFunc(2);
</script>
</BODY>
</HTML>
and the content of test.js is:
if( typeof js_loaded == "undefined" ) {
function A() { alert("constructor of A"); }
A.prototype.CustomFunc=function( p ) { alert("custom func."+p); };
var js_loaded = true;
}
the zip in attachment contains both of these two files
Please, help!
First, about the environment:
- The web pages automatically generated.
- Pages can be inserted to each other
- When a subpage to be inserted is being generated, it does not know will it be inserted or not.
- That because each subpage uses the <script src=...> tags to load the script it needs.
- in the external script files I'm trying to protect it from repeated execution checking (if(){}) the value of a variable which is created after in the script.
Everything worked fine until I tried to use the .prototype to declare the method of my objects.
In the Internet Explorer, I got "Object does not support this property or method", on the access to a prototype function, because the prototype of my object was deleted by itself after the second load of the external script.
Here is the code sample:
<HTML><BODY>
<!-- content of the outer page -->
<script language="javascript" src="test.js"></script>
<script>
var a = new A;
a.CustomFunc(1);
</script>
<!-- content of the inserted subpage -->
<script language="javascript" src="test.js"></script>
<script>
var b = new A;
b.CustomFunc(2);
</script>
</BODY>
</HTML>
and the content of test.js is:
if( typeof js_loaded == "undefined" ) {
function A() { alert("constructor of A"); }
A.prototype.CustomFunc=function( p ) { alert("custom func."+p); };
var js_loaded = true;
}
the zip in attachment contains both of these two files
Please, help!