Can you restrict meta reload? - html

so I'm trying to use meta reload to update my website (using the code below) and I was wondering if it was possible to make it reload once after opening the page.
<meta http-equiv="refresh" content="3" >
Why, because looking at a website that refreshes every 3 seconds is really annoying to look at. If you can help, thank you.

#David's comment (original post)
To store values without files and within the webpage. I suggest you encrypt the data because it is visible in the developers console 'local storage'
function holdArray(array){
localStorage.setItem("holdArray", array);
return true;
}
function releaseArray(){
if(localStorage.hasOwnProperty('holdArray')){
return localStorage.getItem("holdArray");
}
}
Set data
holdArray(JSON.stringify(yourvariable));
Get data
let storage = releaseArray();

All I had to do to make it update once when the page was loaded was change index.html to index.php
Thank you with all the help you guys gave me, but this is all I ended up needing to do. I still very much appreciate the effort though.

Related

Creating two html pages in SAPUI5 and executing one or the other depends on the situation

Currently I have my project running as welcomFile the index.html file. This file takes me to an authentication process. The case is that I need to access one of my views but without performing this authentication, that is, I don't want to go through this index.html. To do so, I created another html (index_new.html). Even if I run this last one it always redirects me to the index.html, I don't know if it has to do with how the neo-app.json file is configured. I tried to put in the index.html that if it arrived a parameter in the url to be directed to the index_new.html but without success, it says that the page does not exist. This is what I tried:
<script>
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
window.location.search = urlParams.toString();
const con = urlParams.get('con');
if (con !== ""){
window.open("/index_new.html", "_self");
}
</script>
The only way I have managed to load the path I want is to run the program, it goes to the index.html and once it has loaded, I change the path to the index_new.html/viewthatIwanttoshow and it shows up. Is there any way to run the new index_new.html without having to run the old one?
I also think it's because of the manifest, because from the index_new.html I do it like this, just like in the index.html:
……
<script id="sap-ui-bootstrap>
…
data-sap-ui-resourceroots='{"app.hello”: “./“}’
…
</script>
</head>
<body class="sapUiBody">
<div data-sap-ui-component data-name="app.hello” data-id="container" data-settings='{"id" : “hello”}’ style="height: 100%"></div>
</body>
Maybe I should change the path here but I don't know which one or how to configure it in the manifest.json.
Maybe my question is not clear, if you have any questions please let me know.
My neo-app.json:
"welcomeFile": "/webapp/index.html",
My manifest.json:
"sap.app": {
"id": “app.hello”,
"type": "application",
I can't / don't want to give you a direct answer on your question. But I would like to mention to think about the concept you are going for.
I don't really understand why you want to load different index.html files. It's pretty far away from a best practice scenario - at least with the information I have out of your post.
When we are talking about authentication, mostly you save a token in cookies / browser storage. Then you can check if you are authenticated. If so, use the UI5 router. In every page you want to, you can check for valid authentication / authorization and redirect again to a login page, if you are not.
IMO you shouldn't use two different index.html sites.
I hope this help you to find another way to solve it.

Redirect the person, who has already seen the page

I am looking for help for the following scenario:
I have a website1.com. I would like website1.com to be like a presentation page. I want every person who has seen the page to be redirected automatically to website2.com.
Another way to look at it:
Lets say the page on website1.com contains information, which would be irrelevant for the person, who has already seen it, therefore I want them to be redirect from the page to website2.com cause then i don't loose the visitor, since I own both of those sites.
From the prespective of the visitor:
I land on a website, which I have not visited yet, website1.com. However, if I have already been to website1.com in the past ( cookie registers it ) , then i am redirected to website2.com
Hope how i broke it down is clear for everybody.
Thank you in advance for the help.
If you are using PHP, you could do it that way at the begining of your page:
<?php
if (!isset($_COOKIE['myCookie'])){
setcookie('myCookie', true, time() + (86400 * 30));
}
else{
header('Location: http://www.website2.com');
}
?>
If you are not using PHP, your serverside language surely have a way to set cookie and the logic will be the same. Hope it helped

How to create auto refresh from static html website

I have following problem with my website. I created very simple website for my family (including my grandfather) but they don't know much about internet. That is why I have to create auto refresh when they open a website.
My website is here: http://kartingsiemianowice.pl/ (please don't look at the code, because it was created just for few days).
Can you let me know how can I create refresh when they open a website? Because when I will change something and send these files to FTP then they have to refresh page.
Best HTML code placed in head section of the website works good in all browsers.
<head> <meta http-equiv="refresh" content="60"> </head>
Where meta will say to browser what to do and content is time in seconds.
If you need to transfer your visitor to another domain just use:
<meta http-equiv="refresh" content="2;url=https://mlmos.com/">
where meta will say what to do, content time in seconds, now 2 or as you wish, then order to redirect to any url, in this case mlmos.com
Hope so this simple solution will help!
As Minh Quy stated in the comments, you can use the JS function setInterval or setTimeout
Example below :
setInterval(function(){alert("Hello")}, 3000);
setTimeout(function () {
location.reload();
}, 3000);
The first simple example displays a pop-up alert window every 3 seconds and the second reloads the page after 3 seconds.
So for your purposes, you will need to use this function in conjunction with your existing code to refresh the page when the user visits a specific page or performs a specific action.
Use following code
setTimeout(function () {
location.reload();
}, 1000);
where 1000 is the number of milliseconds to wait before executing the code.

how to post a value to a php page in a facebook app?

I am a noob facebook app developer and I would be very grateful for a little hand-holding getting started by professionals. I created a very simple app. It's only one file (index.php) and it has an html form that posts a value back to index.php to display. It worked before I added a "share to wall" request to the authentication. Now (I guess) there is a redirection before realoading the index.php, so it gets no $_POST value and it doesn't display the entered value. I would be very grateful if somebody would actually check out my app and its code and tell me how to fix it. (I think it's important to mention that it requests permission to post to the user's wall, but actually it doesn't post anything to the wall. I want to add that functionality later.) Here is the app:
https://apps.facebook.com/webszebb/
And here is the code (screenshot):
http://webszebb.hu/indexphp.png
Thanks.
For the sake of simplicity I'd suggest doing something like:
<html header stuff>
<?php
...snip...
if ($_REQUEST['do'] == 'whatever the action is, i.e: action="?foo" would be foo here') {
print('Your previous number was ' . $_POST['my_number']);
} else {
print('form');
}
?>
But to answer your question I'm assuming the $fb->api('/me') probably redirects you.

Disable cache for some images

I generate some images using a PHP lib.
Sometimes the browser does not load the new generated file.
How can I disable cache just for images created dynamically by me?
Note: I have to use same name for the created images over time.
A common and simple solution to this problem that feels like a hack but is fairly portable is to add a randomly generated query string to each request for the dynamic image.
So, for example -
<img src="image.png" />
Would become
<img src="image.png?dummy=8484744" />
Or
<img src="image.png?dummy=371662" />
From the point of view of the web-server the same file is accessed, but from the point of view of the browser no caching can be performed.
The random number generation can happen either on the server when serving the page (just make sure the page itself isn't cached...), or on the client (using JavaScript).
You will need to verify whether your web-server can cope with this trick.
Browser caching strategies can be controlled by HTTP headers. Remember that they are just a hint, really. Since browsers are terribly inconsistent in this (and any other) field, you'll need several headers to get the desired effect on a range of browsers.
header ("Pragma-directive: no-cache");
header ("Cache-directive: no-cache");
header ("Cache-control: no-cache");
header ("Pragma: no-cache");
header ("Expires: 0");
Solution 1 is not great. It does work, but adding hacky random or timestamped query strings to the end of your image files will make the browser re-download and cache every version of every image, every time a page is loaded, regardless of whether or not the image has changed on the server.
Solution 2 is useless. Adding nocache headers to an image file is not only very difficult to implement, but it's completely impractical because it requires you to predict when it will be needed in advance, the first time you load any image that you think might change at some point in the future.
Enter Etags...
The absolute best way I've found to solve this is to use ETAGS inside a .htaccess file in your images directory. The following tells Apache to send a unique hash to the browser in the image file headers. This hash only ever changes when the image file is modified and this change triggers the browser to reload the image the next time it is requested.
<FilesMatch "\.(jpg|jpeg)$">
FileETag MTime Size
</FilesMatch>
If you need to do it dynamically in the browser using javascript, here is an example...
<img id=graph alt=""
src="http://www.kitco.com/images/live/gold.gif"
/>
<script language="javascript" type="text/javascript">
var d = new Date();
document.getElementById("graph").src =
"http://www.kitco.com/images/live/gold.gif?ver=" +
d.getTime();
</script>
I checked all the answers and the best one seemed to be (which isn't):
<img src="image.png?cache=none">
at first.
However, if you add cache=none parameter (which is static "none" word), it doesn't effect anything, browser still loads from cache.
Solution to this problem was:
<img src="image.png?nocache=<?php echo time(); ?>">
where you basically add unix timestamp to make the parameter dynamic and no cache, it worked.
However, my problem was a little different:
I was loading on the fly generated php chart image, and controlling the page with $_GET parameters. I wanted the image to be read from cache when the URL GET parameter stays the same, and do not cache when the GET parameters change.
To solve this problem, I needed to hash $_GET but since it is array here is the solution:
$chart_hash = md5(implode('-', $_GET));
echo "<img src='/images/mychart.png?hash=$chart_hash'>";
Edit:
Although the above solution works just fine, sometimes you want to serve the cached version UNTIL the file is changed. (with the above solution, it disables the cache for that image completely)
So, to serve cached image from browser UNTIL there is a change in the image file use:
echo "<img src='/images/mychart.png?hash=" . filemtime('mychart.png') . "'>";
filemtime() gets file modification time.
I know this topic is old, but it ranks very well in Google. I found out that putting this in your header works well;
<meta Http-Equiv="Cache-Control" Content="no-cache">
<meta Http-Equiv="Pragma" Content="no-cache">
<meta Http-Equiv="Expires" Content="0">
<meta Http-Equiv="Pragma-directive: no-cache">
<meta Http-Equiv="Cache-directive: no-cache">
I was just looking for a solution to this, and the answers above didn't work in my case (and I have insufficient reputation to comment on them). It turns out that, at least for my use-case and the browser I was using (Chrome on OSX), the only thing that seemed to prevent caching was:
Cache-Control = 'no-store'
For completeness i'm now using all 3 of 'no-cache, no-store, must-revalidate'
So in my case (serving dynamically generated images out of Flask in Python), I had to do the following to hopefully work in as many browsers as possible...
def make_uncached_response(inFile):
response = make_response(inFile)
response.headers['Pragma-Directive'] = 'no-cache'
response.headers['Cache-Directive'] = 'no-cache'
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response.headers['Pragma'] = 'no-cache'
response.headers['Expires'] = '0'
return response
Changing the image source is the solution. You can indeed do this by adding a timestamp or random number to the image.
Better would be to add a checksum of eg the data the image represents. This enables caching when possible.
Let's add another solution one to the bunch.
Adding a unique string at the end is a perfect solution.
example.jpg?646413154
Following solution extends this method and provides both the caching capability and fetch a new version when the image is updated.
When the image is updated, the filemtime will be changed.
<?php
$filename = "path/to/images/example.jpg";
$filemtime = filemtime($filename);
?>
Now output the image:
<img src="images/example.jpg?<?php echo $filemtime; ?>" >
i had this problem and overcoming like this.
var newtags='<div class="addedimage"><h5>preview image</h5><img src="'+one+'?nocache='+Math.floor(Math.random() * 1000)+'"></div>';
I've used this to solve my similar problem ... displaying an image counter (from an external provider). It did not refresh always correctly. And after a random parameter was added, all works fine :)
I've appended a date string to ensure refresh at least every minute.
sample code (PHP):
$output .= "<img src=\"http://xy.somecounter.com/?id=1234567890&".date(ymdHi)."\" alt=\"somecounter.com\" style=\"border:none;\">";
That results in a src link like:
http://xy.somecounter.com/?id=1234567890&1207241014
If you have a hardcoded image URL, for example: http://example.com/image.jpg you can use php to add headers to your image.
First you will have to make apache process your jpg as php.
See here:
Is it possible to execute PHP with extension file.php.jpg?
Load the image (imagecreatefromjpeg) from file then add the headers from previous answers. Use php function header to add the headers.
Then output the image with the imagejpeg function.
Please notice that it's very insecure to let php process jpg images. Also please be aware I haven't tested this solution so it is up to you to make it work.
Simple, send one header location.
My site, contains one image, and after upload the image, there not change, then I add this code:
<?php header("Location: pagelocalimage.php"); ?>
Work's for me.