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


Groups > comp.lang.javascript > #37805 > unrolled thread

Calling an include file by using JavaScript ?

Started bydr.j.r.stockton@gmail.com
First post2019-11-17 12:52 -0800
Last post2019-11-19 11:54 +0100
Articles 8 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#37805 — Calling an include file by using JavaScript ?

Fromdr.j.r.stockton@gmail.com
Date2019-11-17 12:52 -0800
SubjectCalling an include file by using JavaScript ?
Message-ID<9bab4aea-6cd1-4c20-a953-8f02509189af@googlegroups.com>
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>

Can I get the same inclusion, with a little respectable
standards-compliant code, by putting a bit more script in C.js ;
and if so how?

The reason is that C.js is essentially a programmer's file whereas
D.js will be a site designer's data set, and they should be edited
separately. The code for using the data set can be in either C.js
or D.js.

The data set will be represented as a single Object, and will be
a neat list of lists of items, one quoted string per line, with
the string on each line, and the entire set of lines, being
preceded and followed with such punctuation as makes the whole
into an Object - possible example (with nonsense data) an array
of arrays :

var A = [
["cat",
 "pig",
 "dog"],
["1",
 "2",
 "3",
 "4"],
["nail",
 "rivet"]
]


I think this might be a part of page-coding that I've not
yet found.


-- 
  (c) John Stockton, near London, UK.  Using Google Groups.           |
 Mail: J.R.""""""""@physics.org - or as Reply-To, if any.             |

[toc] | [next] | [standalone]


#37806

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2019-11-17 22:47 +0100
Message-ID<XnsAB0AE7E4C90A5eejj99@194.109.6.166>
In reply to#37805
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)

[toc] | [prev] | [next] | [standalone]


#37808

Fromdr.j.r.stockton@gmail.com
Date2019-11-18 10:00 -0800
Message-ID<aa163932-19f0-471a-a089-03658d17f307@googlegroups.com>
In reply to#37806
On Sunday, 17 November 2019 21:48:20 UTC, Evertjan.  wrote:
> JRS wrote on 17 Nov 2019 in comp.lang.javascript:

> > ...

> Add this to the code in C.js:

> ...

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


Thanks, that seems fine; a (test) alert call at the start of D.js is called, and the code in D.js gives an expected error message (that code so far is pseudo-code written in valid JavaScript. [ Here, D is short for INC-LOOP ]

> Much more versatile imho is, 
> to do this with serverside includes

Serverside not at present available, and for some of the work will not exist.

I did try writing the variables in Dutch, in your honour; but I found it confusing and have kept only Kettingen.



On Sunday, 17 November 2019 21:48:50 UTC, Ben Bacarisse  wrote:
> JRS writes:
> ...
> If you can rely on them being supported, ECMAScript modules are probably
> the way to go.
> Ben.

I know nothing of those, and prefer to use nothing much more than I already know.  But I'll bear it in mind, thanks.

-- 
  (c) John Stockton, near London, UK.  Using Google Groups.           |
 Mail: J.R.""""""""@physics.org - or as Reply-To, if any.             |

[toc] | [prev] | [next] | [standalone]


#37811

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2019-11-19 11:41 +0100
Message-ID<XnsAB0C76DD2CADCeejj99@194.109.6.166>
In reply to#37808
dr.j.r.stockton@gmail.com wrote on 18 Nov 2019 in comp.lang.javascript:

> On Sunday, 17 November 2019 21:48:20 UTC, Evertjan.  wrote:
>> JRS wrote on 17 Nov 2019 in comp.lang.javascript:
> 
>> > ...
> 
>> Add this to the code in C.js:
> 
>> ...
> 
>> let fileref = document.createElement('script');
>> fileref.type = 'text/javascript';
>> fileref.src = 'D.js';
>> document.querySelector('head').appendChild(fileref);
> 
> 
> Thanks, that seems fine; a (test) alert call at the start of D.js is
> called, and the code in D.js gives an expected error message (that code
> so far is pseudo-code written in valid JavaScript. [ Here, D is short
> for INC-LOOP ] 

Ensure the htmlpage has, next to the link to C.js with the above: 

<body>First line

And fill, for testing, D.js with:

document.body.innerHTML += '<br>Jet another line';

>> Much more versatile imho is, 
>> to do this with serverside includes
> 
> Serverside not at present available, and for some of the work will not
> exist. 
> 
> I did try writing the variables in Dutch, in your honour; but I found it
> confusing and have kept only Kettingen. 

The advantage of Dutch variable names is,
next to the joy of it,
that you are less bothered with 'reserved' words.

> Dutch, in your honour

Thank you, 
I take somewhat less pride than usual in being British, these days.

What letting Gaelic and Cymraeg variable names 'de honneurs waarnemen'?

<https://www.nrc.nl/nieuws/2005/12/13/de-honneurs-waarnemen-11055631-
a1151289>

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

[toc] | [prev] | [next] | [standalone]


#37809

Fromdr.j.r.stockton@gmail.com
Date2019-11-18 15:36 -0800
Message-ID<3a1701e7-44c4-4a59-9527-b416ea789517@googlegroups.com>
In reply to#37806
On Sunday, 17 November 2019 21:48:20 UTC, Evertjan.  wrote:
> JRS 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:
> 
> ...
>
> let fileref = document.createElement('script');
> fileref.type = 'text/javascript';
> fileref.src = 'D.js';
> document.querySelector('head').appendChild(fileref);


I did that, and "D.js" now contains (note that all participating
pages have identical button elements; the button says "GO" but
does not know where to) :-


// In each of these pages, put something like
// <input type=button value="Next" onClick="NextPage()">

var Kettingen = [
 "JS-DATE0.HTM",
// "JS-DATE1.HTM",
// "JS-DATE2.HTM",
 "JS-DATE3.HTM",
 "JS-DATE9.HTM",
 "JS-DATE0.HTM"]

function NextPage(ThisPage) { var M, NP, J
  M = location.href.match(/(.*\/)(.*)/)
  NP = M[2].toUpperCase()
  for (J = 0 ; J < Kettingen.length ; J++)
    if (Kettingen[J] == NP) { location.href = Kettingen[J+1] ; return }
  alert("Failure in function NextPage, in INC-LOOP.JS")
  }


It is currently required that all pages listed are in the same
directory; a slight limitation at present.

One can put multiple loops in one Kettingen; but for each loop
of pages, as Google Search can be persuaded to say, "THE LAST
SHALL BE FIRST AND THE FIRST SHALL BE LAST", which, more or less,
can be found (by those who have that Book) in the Gospel
according to St Matthew, at the end of Chapter 19.

-- 
  (c) John Stockton, near London, UK.  Using Google Groups.           |
 Mail: J.R.""""""""@physics.org - or as Reply-To, if any.             |

[toc] | [prev] | [next] | [standalone]


#37807

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2019-11-17 21:48 +0000
Message-ID<87d0dqi37t.fsf@bsb.me.uk>
In reply to#37805
dr.j.r.stockton@gmail.com writes:

> 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>
>
> Can I get the same inclusion, with a little respectable
> standards-compliant code, by putting a bit more script in C.js ;
> and if so how?

If you can rely on them being supported, ECMAScript modules are probably
the way to go.

The old hack was to write code that adds a <script> element to the head
of the document.

<cut>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#37810

FromArno Welzel <usenet@arnowelzel.de>
Date2019-11-19 11:37 +0100
Message-ID<h3huvcFkbutU1@mid.individual.net>
In reply to#37807
On 17.11.19 22:48, Ben Bacarisse wrote:

> dr.j.r.stockton@gmail.com writes:
> 
>> 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>
>>
>> Can I get the same inclusion, with a little respectable
>> standards-compliant code, by putting a bit more script in C.js ;
>> and if so how?
> 
> If you can rely on them being supported, ECMAScript modules are probably
> the way to go.

Also see here:

<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules>


-- 
Arno Welzel
https://arnowelzel.de

[toc] | [prev] | [next] | [standalone]


#37812

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2019-11-19 11:54 +0100
Message-ID<XnsAB0C7916DCF48eejj99@194.109.6.166>
In reply to#37810
Arno Welzel <usenet@arnowelzel.de> wrote on 19 Nov 2019 in 
comp.lang.javascript:

>> If you can rely on them being supported, ECMAScript modules are probably
>> the way to go.
> 
> Also see here:
> 
> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules>

Interesting as a play-thing, 
real-life usefullness yet to be considered overhere.

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web