By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,926 Members | 1,833 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,926 IT Pros & Developers. It's quick & easy.

reloading JS

P: n/a
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

Oct 25 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

Oct 25 '06 #2

P: n/a

R wrote:
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.

Oct 25 '06 #3

P: n/a
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
Oct 25 '06 #4

P: n/a
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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 25 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.