reloading JS

R

R

Hi All,

I have a problem with reloading JS.

I have a DIV where I placed JS code displaying random tricks & tips
from other site.

at the beggining I had it this way:

<div id="tips">
<script src="http://other.site.com/random_tt.php"></script>
</div>

it works without any problem, random tip is displayed.

I wanted to change tips and tricks every 5 minutes, I wrote:

setTimeout('change_tips()', 1000 * 60 * 5);

in change_tips function I have:

new_tt = document.getElementById('tips');
new_tt.innerHTML = '<script
src="http://other.site.com/random_tt.php"></script>;

but... random tips are generated this way (the output of PHP script):

tip = 'some content'
document.write(tip)

it uses document.write to display random tip

how can I reload JS with document.write?

thanks in advance
best regards
R
 
S

shimmyshack

the easy way would be to use HTML: an iframe which calls a frameset
which refreshes every 5 mins, the content of which is just a child
frame which is the javascript from the other site.

the harder way is to use js to create and populate the iframe. using
dom compliant code.

my preferred way would be to write a php script on your own server
which gets the code from the other server, and then sanitizes it! I
mean if they get hacked you get hacked, since you are just
document.writing it straight into yuor webpage.
Using php you could use a regular expression to get only text from
within ( ) and then spit that out as a js string variable
var sanitized_tip = 'never include content from other peoples sites
without being very careful';
you would then use the javascript you are currently using and set
sanitized_tip as the text you want to display in the div you have.
 
P

Paul

R said:
Hi All,

I have a problem with reloading JS.

I have a DIV where I placed JS code displaying random tricks & tips
from other site.

at the beggining I had it this way:

<div id="tips">
<script src="http://other.site.com/random_tt.php"></script>
</div>

it works without any problem, random tip is displayed.

I wanted to change tips and tricks every 5 minutes, I wrote:

setTimeout('change_tips()', 1000 * 60 * 5);

in change_tips function I have:

new_tt = document.getElementById('tips');
new_tt.innerHTML = '<script
src="http://other.site.com/random_tt.php"></script>;

but... random tips are generated this way (the output of PHP script):

tip = 'some content'
document.write(tip)

it uses document.write to display random tip

how can I reload JS with document.write?

thanks in advance
best regards
R
I'm probably gonna get flamed for this but, I'm going to suggest
loading the tips in an iframe, so the doc.write will only overwrite the
iframe.
 
G

Guy

R a écrit :
Hi All,

I have a problem with reloading JS.

I have a DIV where I placed JS code displaying random tricks & tips
from other site.

at the beggining I had it this way:

<div id="tips">
<script src="http://other.site.com/random_tt.php"></script>
</div>

it works without any problem, random tip is displayed.

I wanted to change tips and tricks every 5 minutes, I wrote:

setTimeout('change_tips()', 1000 * 60 * 5);

in change_tips function I have:

new_tt = document.getElementById('tips');
new_tt.innerHTML = '<script
src="http://other.site.com/random_tt.php"></script>;

but... random tips are generated this way (the output of PHP script):

tip = 'some content'
document.write(tip)

it uses document.write to display random tip

how can I reload JS with document.write?

thanks in advance
best regards
R
Bonjour,
innerHTML is a bad way ! (script isn't executed)

the simplest method :
use method .reload the entire document in function change_tips !

G
 
R

Randy Webb

R said the following on 10/25/2006 9:45 AM:
Hi All,

I have a problem with reloading JS.

I have a DIV where I placed JS code displaying random tricks & tips
from other site.

at the beggining I had it this way:

<div id="tips">
<script src="http://other.site.com/random_tt.php"></script>
</div>

it works without any problem, random tip is displayed.

I wanted to change tips and tricks every 5 minutes, I wrote:

setTimeout('change_tips()', 1000 * 60 * 5);

in change_tips function I have:

new_tt = document.getElementById('tips');
new_tt.innerHTML = '<script
src="http://other.site.com/random_tt.php"></script>;

And your new script never gets executed (unless you are using a very
early NS6 browser). Script elements inserted via innerHTML don't get
executed.
but... random tips are generated this way (the output of PHP script):

tip = 'some content'
document.write(tip)

it uses document.write to display random tip

how can I reload JS with document.write?

Without using either an IFrame to hold your tips (set the borders to 0
and no margins, you can effectively "hide" an IFrame so that it doesn't
appear to be an IFrame), or, you will have to have a script on your own
server that gets the file from the remote server, removes the
document.write statement, and then you can load the JS and insert the
tips. Seems like a lot of trouble, just make your own tips file and
randomly display them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top