Imagine I have a public display, showing a browser displaying a web page.
Is it possible to send a GET or POST from a mobile device to an HTTP server which triggers some AJAX/pubsub/websocket JavaScript function that changes the page that is presently being viewed on the display, or even just changing an iframe's current domain?
Cross-domain pushstate? Is this at all possible even on your own setup?
Assuming you control the web page being shown on the public display, yes.
The web page would need to either periodically contact the server via AJAX, or have a long-running connection to the server (i.e. Comet or WebSockets).
When the server receives the request from the mobile device, it either uses the Comet connection to send the new URL to the web page, or when the web page next contacts it via AJAX, it sends the new URL in response.
The web page then sets its own window.location property to this new URL.
Note that once it's done this, you'll no longer be able to send the browser in question to another new page, unless the page that you've just sent it to also includes the JavaScript that contacts your server.
But if you don't control the web page being displayed...
Then you'd need a browser extension to initiate the connection between the browser and your server.
You can do this with JavaScript on the client side. This is covered pretty well in that question: Updating address bar with new URL without hash or reloading the page
Unfortunately, it's a relatively new, and mostly unsupported feature. Your alternative is to set the hashtag and use it for navigation.
UPDATE:
If you are trying to "push" pages to the user like a TV channel, then you can have an AJAX request poll the server every few seconds to see if there's a new page. The server would respond with the new URL. You could then put that page in an iFrame.
Related
Is there a way to keep a webpage in a loading state?
I thought of sending resource request to web server and making the web server not send anything back. However I would like to find a solution that can be controlled from the client side.
Calling javascript function window.location.assign(url); almost does my job except for one problem - Firefox and Chromium do not send out cookie to server. Server can not determine access privileges without cookies.
How do I send cookies along with URL as the request to server and open a download window without navigating away from the page?
[Edit] This an invalid question. Please ignore it! Browsers do send cookies along with the URL to server. It is my server code that fails to catch the incoming cookies.
I am writing some js code to send user-page interaction data to analytics server. I am in this context:
No Google analytics.
No third party library.
And I need to achieve:
shouldn't block user navigation. (or as invisible as possible)
should ensure each request is sent to the server.
should be universal, not servlet solution for one site.
Currently what I observed from making a normal AJAX request is when I navigate to another page, the request is canceled from browser side, which indicated data loss.
Any comment/answer is welcome.
I was learning about custom protocols for few days, and there's one thing that I don't understand.
I know how to start an app with custom protocol, but My question is,
Is it possible to get apps response and print it in Web Browser using javascript?
For example If I will send request to protocol myapp:// , that will open an app written in C#, and that app will return string "This is response" can to print it in Web Browser?
If so, can you help me to accomplish it?
Thanks in advance.
Internet protocols aren't all about browsers.
mailto: causes an action in an email program (e.g. start a new email)
ftp: causes an action in an FTP program (which might be integrated into a web browser or Windows Explorer)
gopher: (well, that's not really prevalent anymore)
myapp:// will cause your (C#) app to start running. At that point, it can do anything a C# app can do. One thing it could choose to do is create a .html file on disk, and use
Process.Start("file://Path/To/My.html")
to cause the default web browser to open the document it just created.
UPDATE
You can certainly have your myapp:// protocol handler send an update to the web server that hosts the page in question. My assumption here is that the myapp:// handler is running on a client machine, and there is a web server on a different URL http://mydomain.com serving a page that includes a myapp:// reference.
Web server renders a page that includes both a myapp:// URL and Ajax code to periodically query the web server for updates to part of the HTML body.
User clicks the myapp:// URL
Protocol handler runs
Protocol handler sends an update to the web server, e.g. http://mydomain.com?user=joe&result=123
Web server uses ?user=joe&result=123 to update response next time the Ajax callback is initiated
Ajax callback gets updated data for page from web server, updates page.
Here is the problem:
I have a web application - a frequently changing notification system - that runs on a series of local computers. The application refreshes every couple of seconds to display the new information. The computers only display info, and do not have keyboards or ANY input device.
The issue is that if the connection to the server is lost (say updates are installed and a server must be rebooted), a page not found error is displayed). We must then either reboot all computers that are running this app, OR add a keyboard and refresh the browser, OR try to access each computer remotely and refresh the browser. None of these are good options and result in a lot of frustration.
I cannot change the actual application OR server environment.
So what I need is some way to test the call to the application, and if an error is returned or it times out, continue trying every minute or so until the connection is reestablished.
My idea is to create a client-side page scraper, that makes a JS request to the application (which displays basic HTML), and can run locally on the machine, no server required. If the scrape returns the correct content, it displays it. If not it continues to request the page until the actual page content is returned.
Is this possible? What is the best way to do it?
Instead of scraping, check the status code in the response from the server. if it's not 200 or 304, you've received an error page and should try again.
Check out this link: http://www.ibm.com/developerworks/web/library/wa-ajaxintro3/#N102DB