Im new with ejs. As I was trying out an app. I want to refresh the page every 5 sec.
I got a code
<script language="javascript" type="text/javascript">
$(document).ready(function() {
setInterval("location.reload(true)", 5000);
});
</script>
But how to include jquery in ejs? How to embed this code in ejs page?
Try this
tags: <meta http-equiv="refresh" content="5">. That simple. The "5" is the number of seconds. If you want to increase the time to say 20 minutes, you simply put in "1200" and so on.
Related
I want to refresh an HTML page every hour automatically in the background. I was thinking about using PHP but I'm not sure what if that's possible.
This is all the I have:
<meta http-equiv="refresh" content="3600" >
But this doesn't refresh automatically in the background. How can I do this? If this is possible in PHP and a cron job please let me know (with code preferably). Thank you.
You can use javascript setInterval();
<script>
$(document).ready(function(){
setInterval(function(){ reload_page(); },60*60000);
});
function reload_page()
{
window.location.reload(true);
}
</script>
Try this :
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "3600";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
Refer to this answer https://stackoverflow.com/a/19807718/6390490
Refresh document every 300 seconds using HTML Meta tag
EDIT: for background you have to use ajax something like this https://stackoverflow.com/a/25446696/6390490
function loadlink(){
$('#links').load('test.php',function () {
$(this).unwrap();
});
}
loadlink(); // This will run on page load
setInterval(function(){
loadlink() // this will run after every 5 seconds
}, 5000);
for server side refreshing use
header("Refresh: 300;url='http://thepage.com/example'");//set time here as per your need
I want to show real time data, currently i used this code
<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_updates').load('comment.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
</script>
<head>
<body>
<div id="load_updates"></div>
</body>
Now everything is fine, this code is working and shows data from comment.php, but the problem is that it refreshes data after 10 seconds and it's too much time. I tried to reduce the milliseconds but it's not working
There are some technologies to build a real time application. You can use WebSockets for example.
This link has some options:
https://entwickler.de/webandphp/building-realtime-web-apps-with-php-125787.html
This question already has answers here:
auto refresh for every 5 mins
(4 answers)
Closed 7 years ago.
I am currently using an html page for a webview within my iOS and Android apps. I don't want to update the native code and was wondering if I could just refresh the homepage which is index.html every 2 mins? Is it possible?
You can use:
<meta http-equiv="refresh" content="120">
The <meta http-equiv="refresh"> tag causes a web page to refresh
automatically after a specified amount of time. Users generally don't
expect automatic refreshes, so they can be disorienting. Refreshing
also moves focus to the top of the page, which may frustrate or
confuse users, particularly those who rely on screen readers or other
assistive technologies.
https://web.dev/meta-refresh/
Meta equiv refresh
You can try to use like this:
<meta http-equiv="refresh" content="120">
or you can use setInterval like this:
setInterval(function() {
window.location.reload();
}, 120000);
use this
setTimeout(function(){
window.location.reload(1);
}, 120000);
EDIT
Put this in head
<script>
setTimeout(function(){
window.location.reload(1);
}, 120000);
</script>
EDIT
to attach this function only when page is ready use this
<script>
$('document').ready(function(){
setTimeout(function(){
window.location.reload(1);
}, 120000);
});
</script>
You can Put meta tag before html start
e.g.
<meta http-equiv="refresh" content="120">
<html>
<head>
<meta charset="UTF-8">
<title>Mart</title>
I'm trying to make a simple gallery page. The website will always reload after pressing "Next" and I want to make some prerender for the next slide (for better performance and faster load).
At the moment I'm using prefetch/prerender options from HTML5, for Chrome and FireFox:
<!DOCTYPE html>
<html>
<head>
<link rel="prefetch" href="index2.html">
<link rel="prerender" href="index2.html">
</head>
<body>
<img src="big_big_buck_bunny.jpg"/>
Next
</body>
</html>
Is there any other way to cache/prerender next page (in this example - index2.html) ? For example using JavaScript? I'm asking about it because I want to make the prerender work also on Opera 12 and IE (8/9).
Maybe use AJAX. In jquery exists .load() method (http://api.jquery.com/load/)
$('#next').click(function () {
$('#container').load('http://fiddle.jshell.net/webdevem/JfcJp/show/');
});
$('#prev').click(function () {
$('#container').load('http://fiddle.jshell.net/webdevem/JfcJp/show/ #specialContent');
});
Here You have example jsfiddle
If your going to navigate to a new page there's no way to precache html. That's what Ajax is for.
You can Ajax in the html, set the document body to the new html. But if the use reloads the page it will be at the wrong place unless you set a #! In the URL. There's not a lot of nice options with IE8.
Cant you see just preload the images, The page itself isnt gona take any time to build...is it?
I have a meta http-equiv="refresh" inside the <head>.
<head>
<meta name="mymeta" http-equiv="refresh" content="2" id="myMeta">
</head>
Using Javascript, I'm trying to change the content attribute of this meta tag.
var myMeta = document.getElementById("myMeta");
myMeta.content="10";
When I display the content via document.write(myMeta.content);, I get the changed value which is 10, however, the meta tag will keep refreshing each 2 seconds.
I have tested this both in Firefox and Opera.
FULL PAGE
<!DOCTYPE html>
<html>
<head>
<meta name="mymeta" http-equiv="refresh" content="2" id="myMeta">
<script>
var myMeta=document.getElementById("myMeta");
myMeta.content="10";
document.write(myMeta.content);
</script>
</head>
<body>
</body>
</html>
This happens because the browser immediately process the <meta> tag when it is present onload.
See DEMO.
When the document is being loaded, the browser sees and processes the following:
<meta name="mymeta" http-equiv="refresh" content="2" id="myMeta"/>
Even though you try to change its content from 2 to 10, that 2 second refresh is already acknowledged and the browser waits for 2 seconds before it refreshes the page. The 10-second refresh that is injected by JavaScript actually works*, although the page has been refreshed by the time it reaches 2 seconds and nothing seems to happen. This process is then repeated again and again.
Try the opposite and see what happens.
*This only works on Safari and Chrome. Firefox and Opera does not support the modification of meta refresh through JavaScript.
The getElementsByTagName method returns a NodeList so you need to specify an index to correctly access the element:
var myMeta = document.getElementsByTagName("meta")[0];
As someone mentioned this will probably still not work as the meta tag will need to be re-appended to have the desired effect.
Since you're using JavaScript you can just use setTimeout to achieve the same behavior
setTimeout(function() {
location.reload();
},2000); // reload page after 2 seconds