JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2061
Number of posts: 5164

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Include file Posted by compuchip on 18 May 2002 at 2:36 AM
In a lot of languages you have a syntax like
#include <file>
require "file"
@import url('style.css');
<SCRIPT SRC="explorer.js"></SCRIPT>

Is there a function like that in JavaSCript?
E.g. I have two files with the same functions, but different implementations. Is it possible to do something like:
<SCRIPT>
 // Some code that checks browser and 
 // sets isMSIE to true if IE else sets isMSIE to false
 // Anyway, you get the point, I guess

 // Check browser
 if (isMSIE)  // Load functions for explorer
  include('explorer.js');
 else        // Load functions for other browser
  include('notmsie.js');
</SCRIPT>
<BODY onLoad="onLoadFunction();">

the onLoadFunction is defined in both of the files, so the appropriate function is called when the page is loaded.
Any help would be greatly appreciated.
Report
Re: Include file Posted by Darius on 19 May 2002 at 2:50 PM
This message was edited by the Darius at 2002-5-19 14:56:18

: In a lot of languages you have a syntax like
: #include <file>
: require "file"
: @import url('style.css');
: <SCRIPT SRC="explorer.js"></SCRIPT>
:
: Is there a function like that in JavaSCript?
: E.g. I have two files with the same functions, but different implementations. Is it possible to do something like:
:
: <SCRIPT>
:  // Some code that checks browser and 
:  // sets isMSIE to true if IE else sets isMSIE to false
:  // Anyway, you get the point, I guess
: 
:  // Check browser
:  if (isMSIE)  // Load functions for explorer
:   include('explorer.js');
:  else        // Load functions for other browser
:   include('notmsie.js');
: </SCRIPT>
: <BODY onLoad="onLoadFunction();">
: 

: the onLoadFunction is defined in both of the files, so the appropriate function is called when the page is loaded.
: Any help would be greatly appreciated.
:

You do realize you answered your own question.

if(isMSIE) document.write("<SCR"+"IPT SRC=explorer.js></SCR"+"IPT>");
else document.write("<SCR"+"IPT SRC=notmsie.js></SCR"+"IPT>");

The reason I broke the <SCRIPT></SCRIPT> tags apart is because I didn't want the parser to think that the </SCRIPT> embedded in the string was the end of the <SCRIPT> block.

"We can't do nothing and think someone else will make it right."
-Kyoto Now, Bad Religion






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.