Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #37806

Re: Calling an include file by using JavaScript ?

Newsgroups comp.lang.javascript
Subject Re: Calling an include file by using JavaScript ?
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <9bab4aea-6cd1-4c20-a953-8f02509189af@googlegroups.com>
Date 2019-11-17 22:47 +0100
Message-ID <XnsAB0AE7E4C90A5eejj99@194.109.6.166> (permalink)

Show all headers | View raw


dr.j.r.stockton@gmail.com wrote on 17 Nov 2019 in comp.lang.javascript:

> I have many local pages with the following line in the HEAD
> element :
>    <script type="text/javascript" src="C.js"></script>
> 
> I want to add some constant Javascript to each of those pages;
> I could do it by putting next a line :
>    <script type="text/javascript" src="D.js"></script>

Add this to the code in C.js:

var fileref = document.createElement('script');
fileref.setAttribute('type','text/javascript');
fileref.setAttribute('src', 'D.js');
document.getElementsByTagName('head')[0].appendChild(fileref);

or more modern:

let fileref = document.createElement('script');
fileref.type = 'text/javascript';
fileref.src = 'D.js';
document.querySelector('head').appendChild(fileref);

=========

Much more versatile imho is, 
to do this with serverside includes
[ASP-example]:

<script type='text/javascript'>
<!-- #include virtual ="/js/C-js.asp"-->
</script>

and in C-js.asp:

// Js code
<!-- #include virtual ="/js/D-js.asp"-->





-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Calling an include file by using JavaScript ? dr.j.r.stockton@gmail.com - 2019-11-17 12:52 -0800
  Re: Calling an include file by using JavaScript ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-11-17 22:47 +0100
    Re: Calling an include file by using JavaScript ? dr.j.r.stockton@gmail.com - 2019-11-18 10:00 -0800
      Re: Calling an include file by using JavaScript ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-11-19 11:41 +0100
    Re: Calling an include file by using JavaScript ? dr.j.r.stockton@gmail.com - 2019-11-18 15:36 -0800
  Re: Calling an include file by using JavaScript ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-11-17 21:48 +0000
    Re: Calling an include file by using JavaScript ? Arno Welzel <usenet@arnowelzel.de> - 2019-11-19 11:37 +0100
      Re: Calling an include file by using JavaScript ? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-11-19 11:54 +0100

csiph-web