I'm working with a nice little Jquery that auto loads and refreshes a div every bla bla Seconds.
Works perfectly on all browsers then I load up IE and bang what a surprise no luck! :(
Index.html
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load').load('reload.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
<body>
<div id="load"> </div>
</body>
</script>
reload.php
<?
echo time(); //just a timestamp example..
?>
Any ideas guys?
Add a random value at the end of the url to avoid caching.. That should solve your problem. ex: $('#load').load('reload.php?_=' +Math.random()).fadeIn("slow");
Try closing your script tag before having your body tag.
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load').load('reload.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
</script>
</head>
<body>
<div id="load"> </div>
</body>
body {text-align:center; background-image: url('http://cdn3.crunchify.com/wp- content/uploads/2013/03/Crunchify.bg_.300.png')}
$(document).ready(function() {
auto_refresh();
});
function auto_refresh(){
var randomnumber = Math.floor(Math.random() * 100);
$('#show').text('I am getting refreshed every 3 seconds..! Random Number ==> '+ randomnumber);
}
var refreshId = setInterval(auto_refresh, 1000);
Related
FYI, I am not at all a programmer so anything will have to spelled out clearly.
I am using this .js script inside sharepoint. It works fine!
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>ColorBox demo</title>
<link rel="stylesheet" href="http://www.jacklmoore.com/colorbox/example1/colorbox.css" />
</head>
<body>
<h1>Hello, there!</h1>
<h2>This is some content</h2>
<p>The popup will open in five seconds</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://www.jacklmoore.com/colorbox/jquery.colorbox.js"></script>
<script>
function openColorBox(){
$.colorbox({iframe:true, width:"40%", height:"30%", href: "http://172.16.96.254/pf17.html"});
}
setTimeout(openColorBox, 5000);
setTimeout(parent.$.colorbox.close, 15000);
</script>
</body>
</html>
I have created several Pages on a local internal site. pf1.html - pf21.html
I would like to randomize these when the popup runs.
I have seen this function..posted in this forum.
(Math.random()*11)
How can I add this to the above script and randomize the pages.
This is the full random clip
$(document).ready(function() {
$("a.colorbox").click(function() {
$(this).attr("href","print"+Math.floor(Math.random()*11)+".html");
});
I know the *11 sets the number of pages..
Try something like:
function openColorBox(){
var urlBase = "http://172.16.96.254/pf";
var urlPage = Math.floor(Math.random() * 21);
var urlExt = ".html";
var randomizedURL = urlBase + urlPage + urlExt;
$.colorbox({iframe:true, width:"40%", height:"30%", href: randomizedURL});
}
setTimeout(openColorBox, 5000);
setTimeout(parent.$.colorbox.close, 15000);
I want when page loaded get timeStamp but I can't.
This is my code :
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p id = "x">time</p>
<script src="jquery/jquery1.12.js"></script>
<script>
$(document).ready(function(event){
$("#x").text(event.timeStamp);
})
</script>
</body>
</html>
You can use Date object to do this work. now() method return timestamp in miliseconds. Of course javascript return timestamp with client time.
$(document).ready(function(event){
var timeStamp = Math.floor(Date.now() / 1000);
$("div").text(timeStamp);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div></div>
You will not get event object in ready call. As a workaround you can use $.now() for instance:
$(document).ready(function(){
$("#x").text($.now());
});
<html>
<head>
<script type="text/javascript" language="JavaScript">
var inter;
var seconds = 1;
function recharge()
{
inter = window.setInterval( "printA()" , 1000 );
}
function printA()
{
document.write( "you are here: " + seconds + " seconds" );
seconds++;
}
</script>
</head>
<body>
<button onclick="recharge();"> Start </button>
</body>
</html>
my problem is... recharge() contains a setInterval() that contains a function printA() this
function that does is print whit a document.write a variable that sum one every time that recharge
is called.. but just print 1 and doesnt print the next number. I tried whit a alert instead of document.write
and its work so I don't know what i am doing wrong. i am a noob. Thanks for your help.
So as I'm understanding your question and comments, you want to print something like this:
you are here: 2 seconds
you are here: 3 seconds
you are here: 4 seconds
I would recommend doing something like this:
<html>
<head>
<script type="text/javascript" language="JavaScript">
var inter;
var seconds = 1;
function recharge()
{
inter = window.setInterval( "printA()" , 1000 );
}
function printA()
{
document.body.innerHTML += "<div>you are here "+seconds+" seconds</div>";
seconds++;
}
</script>
</head>
<body>
<button onclick="recharge();"> Start </button>
</body>
</html>
The += will keep appending html to the document.
When you document.write(), the whole page is re-written, meaning all your JavaScript is lost. alert() should work however - what did you try? The innerHTML method by winhowes works probably best. Also I don't see what 'recharge();' is supposed to achieve.
I'm trying to setup a script that will change the background of a DIV with each page fresh.
This is my code.
Untitled Document
<script type="text/javascript">
var totalCount = 3;
function ChangeIt()
{
var num = Math.ceil( Math.random() * totalCount );
document.getElementById("content").style.backgroundImage = "url('bgimages/'"+num+"'.jpg')";}
</script>
</head>
<body>
<div id="content">
hello
</div>
<script type="text/javascript">
ChangeIt();
</script>
</body>
</html>
The problem is that it's not changing and I'm getting this error:
Error in parsing value for 'background-image'. Declaration dropped.
I'm not sure what I'm doing wrong.
Thanks in advance!
document.getElementById("content").style.backgroundImage = "url('bgimages/"+num+".jpg')";}
<?php
echo '
<script type="text/javascript">
$(function() {
var refresh = setInterval(function() {
$("#content").html("'.rand().'");
}, 3000);
});
</script>
<div id="content"></div>
';
?>
This will update the div "content" with a random number after 3 seconds, however it only updates once. Why does it not continually generate a new number every three seconds, and how can I make it do precisely that?
Thank you in advance for any assistance rendered.
Ha. PHP is run on the SERVER side. JS is on the client.
you need to generate the rand on the JS side not he php side...
js code:
<script type="text/javascript">
$(function() {
var refresh = setInterval(function() {
var randomnumber = Math.floor(Math.random()*11);
//where 11 dictates that the random number will fall between 0-10
$("#content").html(randomnumber);
}, 3000);
});
</script>
<div id="content"></div>