473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Dynamic include?

Hey hey hey :)

I'd like to do a .js include each X seconds, to update an array (the .js is
really a .php file which generates the javascript dynamically).

Just like <script language="JavaScript" src="..., but in something like a
function call, e.g. "include('mydynamicscript.js');".

Can be done? Yes? No?

TIA,
Daniel :)
--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #1
5 3673
nj
Yep, it's possible.

One way to do this is by giving a script tag an ID, and then use a
timeout to reload the script by altering, or setting the SRC attribute
of the script tag.

Something like this (completely ad hoc and untested) might do the
trick:

-------

<script language="javascript" src="somejscode.php"
id="somejscode"></script>
<script language="javascript">

function refreshScript() {
// if this doesn't work (due to browser caching for instance), try
adding a random querystring parameter to force a refresh
document.getElementById("somejscode").src = "somejscode.php";
}

setInterval ("refreshScript();", 5000); // refresh in 5 seconds

</script>

-------
hope this helps,
J.

Jul 23 '05 #2
nj wrote:
Yep, it's possible.

One way to do this is by giving a script tag an ID, and then use a
timeout to reload the script by altering, or setting the SRC attribute
of the script tag.

Something like this (completely ad hoc and untested) might do the
trick:

-------

<script language="javascript" src="somejscode.php"
id="somejscode"></script>
<script language="javascript">

function refreshScript() {
// if this doesn't work (due to browser caching for instance), try
adding a random querystring parameter to force a refresh
document.getElementById("somejscode").src = "somejscode.php";
}

setInterval ("refreshScript();", 5000); // refresh in 5 seconds

</script>

-------
hope this helps,
J.


Hi NJ :)

Thanks for the reply. Unfortunately, this doesn't work, with our without
adding a bogus variable to the URL (at least not in Firefox). In the
meantime I was fiddling around with loading a helper.html file in an
iframe, and letting the helper page update the script (actually the script
creates an array), then call back to the parent page with the updated
array. This should work, but firefox doesn't really like it
("document.getElementById('helper').location has no properties" or
"document.frames has no properties")... Gonna kick on that for a bit...

Cheers,
Daniel :)

--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #3
DanielEKFA wrote:
array. This should work, but firefox doesn't really like it
("document.getElementById('helper').location has no properties" or
"document.frames has no properties")... Gonna kick on that for a bit...


Of course I was just forgetful, it's .src, not .location.href :) Works fine
now.
--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #4
nj wrote:
Yep, it's possible.

One way to do this is by giving a script tag an ID, and then use a timeout
to reload the script by altering, or setting the SRC attribute of the
script tag.
You mean the `script' ([X]HTML) element which consists of a start tag
(`<script ...>'), content that may be empty and an end tag (`</script>').
Something like this (completely ad hoc and untested) might do the
trick:

-------

<script language="javascript" src="somejscode.php"
id="somejscode"></script>


The `script' element does not have an `id' attribute in HTML, and
since the `type' attribute is missing here this is not even HTML:
The above is not supposed to work.
PointedEars
--
Immerhin weiß ich, daß die durchschnittliche Verkaufsperson kein Abitur
erlitten hat, somit der Sprachwitz bisweilen nicht durch entsprechende
Sachkenntnis gedämpft ist.
-- Martin Gerdes in desd <qr********************************@4ax.com>
Jul 23 '05 #5
Thomas 'PointedEars' Lahn wrote in a message on 07 May 2005 in reply to
a message dated 21 April 2005 and for some reason felt it appropriate to
reply to a message that was dead and gone for over two weeks and babbled
incoherently as follows:
nj wrote:

Yep, it's possible.

One way to do this is by giving a script tag an ID, and then use a timeout
to reload the script by altering, or setting the SRC attribute of the
script tag.

You mean the `script' ([X]HTML) element which consists of a start tag
(`<script ...>'), content that may be empty and an end tag (`</script>').


Who said anything about [X]HTML?
Something like this (completely ad hoc and untested) might do the
trick:

-------

<script language="javascript" src="somejscode.php"
id="somejscode"></script>

The `script' element does not have an `id' attribute in HTML, and
since the `type' attribute is missing here this is not even HTML:


Again, who said anything about [X]HTML? For all you know it could be an
..hta application. Besides, you missed the very important point that
changing the source of a script tag only works in IE. For other
browsers/UA's you have to implement a different strategy.
The above is not supposed to work.


That depends, directly, on your definition of "works". Perhaps if you
bothered to learn what reality is in the world of browsers/UA's you
would realize it does indeed "work" in certain scenarios.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Daniel Keller | last post by:
Hello! I'm trying to set up a page system using "dynamic" SSI. That means that I normally use the following on my website: <!--#include virtual="file.inc" --> Now I want to make this...
4
by: Scott Lyons | last post by:
Hey all, Can someone help me figure out how to pass a dynamic array into a function? Its been giving me some trouble, and my textbook of course doesnt cover the issue. Its probably something...
5
by: meyousikmann | last post by:
I am having a little trouble with dynamic memory allocation. I am trying to read a text file and put the contents into a dynamic array. I know I can use vectors to make this easier, but it has to...
6
by: Materialised | last post by:
Hi Everyone, I apologise if this is covered in the FAQ, I did look, but nothing actually stood out to me as being relative to my subject. I want to create a 2 dimensional array, a 'array of...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
10
by: jflash | last post by:
Hello all, I feel dumb having to ask this question in the first place, but I just can not figure it out. I am wanting to set my site up using dynamic urls (I'm assuming that's what they're...
7
by: Jo | last post by:
Hi, How can i differentiate between static and dynamic allocated objects? For example: void SomeFunction1() { CObject *objectp = new CObject; CObject object;
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
1
by: sreemati | last post by:
Hi Everyone, I have newly started as a ASP developer. I have been working on some change request and was blogged down with dynamic includes. Eventually I had managed to figure out the problem and...
21
by: arnuld | last post by:
I have created a program to print the input words on stdout. Input is taken dynamically from stdin. In each word, each input character is allocated dynamically. I have ran this program with a file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.