473,386 Members | 1,773 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.

reloading JS

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
4 1732
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Greg Bryant | last post by:
Wondering why my setcookies didn't have any impact, I noticed the line in the manual that said the page needs to be reloaded before they take effect (which does make a certain kind of sense). So,...
3
by: jbj | last post by:
Something like a php function that can be called? I have php in a page that needs to be update periodically (basically poll results) without reloading the page around it (I do have a button you...
4
by: J. J. Cale | last post by:
Hi Obviously I'm new to PHP. I would like to be able to update a table in a page from a database on the server without reloading the page each time. Is this possible with PHP? TIA Jimbo
2
by: Andy Jewell | last post by:
Does anyone know of a way to dynamically reload all the imported modules of a client module? I'm writing a program that I have broken down into quite a few submodules, and the 'configuration'...
2
by: aurora | last post by:
I am looking for a way for reloading updated modules in a long running server. I'm not too concerned about cascaded reload or objects already created. Just need to reload module xxx if the...
8
by: Aspersion | last post by:
I'm building an ASP page that has a lot of text and graphics. There is a calculation facility on the page. The user enters several numbers in a form and presses a button to see the calculated...
0
by: Anto | last post by:
Hi, We have a asp and the source is, <% Response.Expires = 0 appnum = Request.QueryString("appnum") pdfpath = Application("pdfpath") set objXML = server.createobject("TASJobReport1.JobReport")...
2
by: Snolly | last post by:
Hi all, Here is my issue. I have a web page (lets call it page1) with an iframe in it that then opens a pop-up window (page2). The pop-up window is used to edit some data that was loaded into...
3
by: Richard | last post by:
Hey there, I have a textbox and a listbox. When a user types a number in the textbox, I want to get all the records from a MS Access DB but without reloading the page. I now have something...
9
by: andrewfelch | last post by:
Hello all, I'm using the metaclass trick for automatic reloading of class member functions, found at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/160164 My problem is that if I 1)...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.