DanielBlais
asked on
reload <script language="javascript" src=...>
I want to reload an include javascript at each x seconds.
It works well in NS6, but do nothing in IE.
Any idea?
Here my code :
<div id="test"></div>
<script language="javascript">
function showInfo()
{
var info;
info = "<scr" + "ipt language='jav" + "ascript' src='rfm-info.htm'></scr" + "ipt>";
document.getElementById("t est").inne rHTML = info;
window.setTimeout("showInf o();",1000 );
}
It works well in NS6, but do nothing in IE.
Any idea?
Here my code :
<div id="test"></div>
<script language="javascript">
function showInfo()
{
var info;
info = "<scr" + "ipt language='jav" + "ascript' src='rfm-info.htm'></scr" + "ipt>";
document.getElementById("t
window.setTimeout("showInf
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
include("http://localhost/myinclude.htm");
so the following works with both MSIE5+ and NS6+
<html>
<head>
<title>Loading Scripts</title>
<script language="javascript">
window.onload = init;
function init() {
eData = document.getElementById("d ata");
if (! document.all) {
eData.innerHTML = "<scr" + "ipt language='jav" + "ascript' src='scripts/data.js'></sc r" + "ipt>";
} else {
eScript = document.createElement("sc ript");
eScript.setAttribute("lang uage","jav ascript");
eData.appendChild(eScript) ;
eScript.setAttribute("src" ,"scripts/ data.js");
}
window.setInterval("loadDa ta();",100 0);
}
function loadData() {
if (! document.all) {
eData.innerHTML = "<scr" + "ipt language='jav" + "ascript' src='scripts/data1.js'></s cr" + "ipt>";
} else {
eScript.setAttribute("src" ,"scripts/ data1.js") ;
}
}
</script>
</head>
<body>
<div id="data"></div>
</body>
</html>
where data.js and data1.js is just to show that you can swap files.
<html>
<head>
<title>Loading Scripts</title>
<script language="javascript">
window.onload = init;
function init() {
eData = document.getElementById("d
if (! document.all) {
eData.innerHTML = "<scr" + "ipt language='jav" + "ascript' src='scripts/data.js'></sc
} else {
eScript = document.createElement("sc
eScript.setAttribute("lang
eData.appendChild(eScript)
eScript.setAttribute("src"
}
window.setInterval("loadDa
}
function loadData() {
if (! document.all) {
eData.innerHTML = "<scr" + "ipt language='jav" + "ascript' src='scripts/data1.js'></s
} else {
eScript.setAttribute("src"
}
}
</script>
</head>
<body>
<div id="data"></div>
</body>
</html>
where data.js and data1.js is just to show that you can swap files.
ASKER
sorry, none of this example works.
b1xml2, your example works the first time, but if I change the source file, it doesn't refresh (seem like an cache problem).
knightEknight, the whole page disappear and only the source of the included file appear.
You can see my page at :
http://213.41.71.8/rfm/rfminfo-main.htm
and
http://213.41.71.8/rfm/rfminfo-main2.htm
b1xml2, your example works the first time, but if I change the source file, it doesn't refresh (seem like an cache problem).
knightEknight, the whole page disappear and only the source of the included file appear.
You can see my page at :
http://213.41.71.8/rfm/rfminfo-main.htm
and
http://213.41.71.8/rfm/rfminfo-main2.htm
DanielBlais,
whether you use XMLHTTP or the SCRIPT element to reload data, it is governed by the browser settings and if the browser settings is not set to check for newer versions on every visit to the page, you may or may not get the data from the server instead of from the cache.
That is where using IFRAMES provides the ability to reload the IFRAME with the option to get the data from the server.
window.frames["myframe"].w indow.loca tion.reloa d(true);
unless of course, you vary the source path e.g.
first pass data.js
second pass data.js?timestamp=20020403 1000
third pass data.js?timestamp=20020403 10000
thus try this for size
======================
<html>
<head>
<title>Loading Scripts</title>
<script language="javascript">
window.onload = init;
function init() {
eData = document.getElementById("d ata");
if (! document.all) {
eData.innerHTML = "<scr" + "ipt language='jav" + "ascript' src='scripts/data.js'></sc r" + "ipt>";
} else {
eScript = document.createElement("sc ript");
eScript.setAttribute("lang uage","jav ascript");
eData.appendChild(eScript) ;
eScript.setAttribute("src" ,"scripts/ data.js?ti mestamp=20 00");
}
window.setInterval("loadDa ta();",200 0);
}
function loadData() {
var szURL = "scripts/data1.js?timestam p=" + getTimeStamp();
//alert(szURL);
if (! document.all) {
eData.innerHTML = "<scr" + "ipt language='jav" + "ascript' src='" + szURL + "'></scr" + "ipt>";
} else {
eScript.setAttribute("src" ,szURL);
}
}
function getTimeStamp() {
var datNow = new Date();
var szDate = datNow.getFullYear();
szDate += (datNow.getMonth() < 9 ? "0" : "") + (datNow.getMonth() + 1);
szDate += (datNow.getDate() < 10 ? "0" : "") + datNow.getDate();
szDate += (datNow.getHours() < 10 ? "0" : "") + datNow.getHours();
szDate += (datNow.getMinutes() < 10 ? "0" : "") + datNow.getMinutes();
szDate += (datNow.getSeconds() < 10 ? "0" : "") + datNow.getSeconds();
switch (String(datNow.getMillisec onds()).le ngth) {
case 2:
szDate += "0";
break;
case 1:
szDate += "00";
}
szDate += datNow.getMilliseconds();
return szDate;
}
</script>
</head>
<body>
<div id="data"></div>
</body>
</html>
whether you use XMLHTTP or the SCRIPT element to reload data, it is governed by the browser settings and if the browser settings is not set to check for newer versions on every visit to the page, you may or may not get the data from the server instead of from the cache.
That is where using IFRAMES provides the ability to reload the IFRAME with the option to get the data from the server.
window.frames["myframe"].w
unless of course, you vary the source path e.g.
first pass data.js
second pass data.js?timestamp=20020403
third pass data.js?timestamp=20020403
thus try this for size
======================
<html>
<head>
<title>Loading Scripts</title>
<script language="javascript">
window.onload = init;
function init() {
eData = document.getElementById("d
if (! document.all) {
eData.innerHTML = "<scr" + "ipt language='jav" + "ascript' src='scripts/data.js'></sc
} else {
eScript = document.createElement("sc
eScript.setAttribute("lang
eData.appendChild(eScript)
eScript.setAttribute("src"
}
window.setInterval("loadDa
}
function loadData() {
var szURL = "scripts/data1.js?timestam
//alert(szURL);
if (! document.all) {
eData.innerHTML = "<scr" + "ipt language='jav" + "ascript' src='" + szURL + "'></scr" + "ipt>";
} else {
eScript.setAttribute("src"
}
}
function getTimeStamp() {
var datNow = new Date();
var szDate = datNow.getFullYear();
szDate += (datNow.getMonth() < 9 ? "0" : "") + (datNow.getMonth() + 1);
szDate += (datNow.getDate() < 10 ? "0" : "") + datNow.getDate();
szDate += (datNow.getHours() < 10 ? "0" : "") + datNow.getHours();
szDate += (datNow.getMinutes() < 10 ? "0" : "") + datNow.getMinutes();
szDate += (datNow.getSeconds() < 10 ? "0" : "") + datNow.getSeconds();
switch (String(datNow.getMillisec
case 2:
szDate += "0";
break;
case 1:
szDate += "00";
}
szDate += datNow.getMilliseconds();
return szDate;
}
</script>
</head>
<body>
<div id="data"></div>
</body>
</html>
just a slight amendment to the init function,
function init() {
eData = document.getElementById("d ata");
if (! document.all) {
eData.innerHTML = "<scr" + "ipt language='jav" + "ascript' src='scripts/data.js'></sc r" + "ipt>";
} else {
eScript = document.createElement("sc ript");
eScript.setAttribute("lang uage","jav ascript");
eData.appendChild(eScript) ;
eScript.setAttribute("src" ,"scripts/ data.js");
}
window.setInterval("loadDa ta();",200 0);
}
function init() {
eData = document.getElementById("d
if (! document.all) {
eData.innerHTML = "<scr" + "ipt language='jav" + "ascript' src='scripts/data.js'></sc
} else {
eScript = document.createElement("sc
eScript.setAttribute("lang
eData.appendChild(eScript)
eScript.setAttribute("src"
}
window.setInterval("loadDa
}
ASKER
I have find a sinple way.
I have add in header of my file.
<%
response.expires = -1
%>
I have add in header of my file.
<%
response.expires = -1
%>
ASKER
Is there a way to give point to 2 persons?
yeah request a split in the Community Support. what they will do is the following.
1. They will reduce the points here and refund the points to you.
2. You award one of the experts here with the split points.
3. You post another question with the refunded points with the title e.g. For expertABCD.
In the post, say something like this:
"For assistance in https://www.experts-exchange.com/jsp/qShow.jsp?qid=20286072"
1. They will reduce the points here and refund the points to you.
2. You award one of the experts here with the split points.
3. You post another question with the refunded points with the title e.g. For expertABCD.
In the post, say something like this:
"For assistance in https://www.experts-exchange.com/jsp/qShow.jsp?qid=20286072"
hmmm, why the grade C when you did not tell us you were using IIS,
FYI.
'This expires the document immediately.
Response.Expires = -1
'This prevents proxy servers from caching the content
Response.CacheControl = "no-cache"
'This tells MSIE to not keep a cache copy
Response.AddHeader "Pragma","no-cache"
The dynamic URL will result in the javascript being called because it is not cached, having been called only once in a lifetime.
FYI.
'This expires the document immediately.
Response.Expires = -1
'This prevents proxy servers from caching the content
Response.CacheControl = "no-cache"
'This tells MSIE to not keep a cache copy
Response.AddHeader "Pragma","no-cache"
The dynamic URL will result in the javascript being called because it is not cached, having been called only once in a lifetime.
The dynamic URL will result in the javascript being called from the server because it is not cached, having been called only once in a lifetime.
whichever moderator that modified this question, kindly note the following.
1. This QID is worth 200 points, why reduce it to 10 points for me? Where is the justice when all I wanted was an equitable outcome for knightEKnight as well in
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=20286462
Please rectify immediately.
1. This QID is worth 200 points, why reduce it to 10 points for me? Where is the justice when all I wanted was an equitable outcome for knightEKnight as well in
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?qid=20286462
Please rectify immediately.
Grade changed, and split recorded per request of Asker.
knightEknight: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20286592
Netminder
CS Moderator
knightEknight: points for you at https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20286592
Netminder
CS Moderator
Netminder, the question is worth 200 points, pls rectify...
my share is 100 points and not 10 points
my share is 100 points and not 10 points
<SCRIPT language='JavaScript'>
function include(url) // must be a fully qualified URL, I don't know why
{
var xml = new ActiveXObject("Microsoft.X
xml.Open( "GET", url, false );
xml.Send()
document.writeln(xml.respo
}
</script>