Force Webpage Refresh From External Page
Solution 1:
You can use WebSockets. For example:
var socket = new WebSocket("ws://javascript.ru/ws");
socket.onmessage = function(event) {
if (event.data == "reload") {
location.reload();
}
};
With WebSockets you can also organize reloading all pages from one of this pages with propagation of event.
WebSockets implement a event-driven architecture. You will implement some handlers for events and messages and just start it. Then you can send events from server or other pages through server and handle it as you like.
Solution 2:
You could define a route to your server that return true or false depending on the need to refresh or not. You would then do on client side :
functioncheckReload() {
$.ajax({
url: "127.0.0.1/needRefresh",
success: function(data) {
if (data == "true")
location.reload();
elsesetTimeout(checkReload, 1000);
}
});
}
setTimeout(checkReload, 1000);
What this code do is every second (setTimeout function), it query the server with ajax to know if page needs to be reloaded, then reload or not depending on server's response.
Solution 3:
On recent browsers, there is an implementation of websockets that allow the server to push data to the clients. It only works on some webservers though (tomcat 7, node.js, etc...) Websocket spec is here.
An other method is the long request in which the client starts an http request, and the server only answers when it has something to send to the client.
More info here.
Solution 4:
With Javascript : No.
With any server side language: yes.You always have the privilages of using a CRON or polling.
Refer:Is "long polling" the most efficient way to create a Web Real Time App?
Post a Comment for "Force Webpage Refresh From External Page"