I have a web page, where i would like to add links using a custom protocol, to open in my desktop application. For example "myprotocol:www.mytestpage.com".
My issue is, how do I detect, using javascript, if the user has registered my protocol?
If for example I use the link above in firefox, withouth having the protocol registered, I am just taken to an error page. Instead I want to show a dialog telling the user to download my application.
As far as I know you cannot tell whether the protocol has been registered or not.
This answer should give you a step in the right direction. https://stackoverflow.com/a/24129863/7326037
Related
I was wondering if there is a way to retrieve the URL scheme of a browser application using javascript (on mobile)?
For example:
You're browsing a web page on your phone using Google Chrome. Would it be possible for that page to run some javascript and retrieve the googlechrome:// scheme?
Thanks!
Edit:
I just found out that the 'navigator' object has a method called 'registerProtocolHandler' which lets websites register themselves as possible handlers for particular protocols.
This comes pretty close to what I need. The only problem is that this requires permission from the person who is visiting the website, which doesn't compliment the flow I'm going for. Also, it doesn't support Safari on iOS..
By the time your JavaScript is running on the webpage, the user's phone has used the URI Scheme (say googlechrome://) to choose a web browser it has installed. The browser then requests your site using a web protocol like http://. This is what window.location.protocol will provide.
So, JavaScript isn't aware of 'schemes' in the sense of 'browser applications'.
However, you can figure out the user's browser from their User Agent and then deduce a possible URI scheme from this. Still, you can't be certain the user didn't just open up Chrome and navigate to your site themselves, without ever tapping a link.
Note that user agents are not always reliable:
users of a browser can change the value of this field if they want (UA spoofing).
if there is a web page which will be inserted into an app, it can be linked to another page within an app when I click somewhere on the web page because of the special link that can only be open within an app. However, if I want to make the same web page be opened within a mobile browser, I have to replace the special link.So,the prerequisite is that I need to detect if the web page is opened within an app or a mobile browser. Anyone can help?
1) Try to read the User Agent header from the http connections headers. It will show you the device that is connecting to your site. (proud to be hacked since header can be changed)
Here you have a php example on how to read user agent
<?php echo $_SERVER['HTTP_USER_AGENT']; ?>
2) Add some logic on your app and on your web page in order to "recognize" each other.
A simple logic could be to add a parameter read on your web page that must have an specific value in order to allow access. Your app must call the url with the expected value on it parameter.
What you're looking for is the user-agent, each browser has a different user agent (name) which generally tells you what sort of device the browser is built for.
There are plenty of ways of retrieving the user agent with javascript check this previous StackOverflow question + answer here.
You can check the browser's useragent, which is a string. MDN
You can access it via Javascript and then perform conditionals based upon the result.
All browsers will return something slightly different so you will need to find something common to reduce the number of branches.
if(window.navigator.userAgent.match(/Android/i) {
//Android browser, do something
}
Bunch of strings here: UserAgent strings
I'm working on an app built in Titanium that has a few "Tweet about this" buttons. Since I can't use the Javascript part of a Tweet button as described in Twitter API, I just use a plain URL with parameters.
On Android, this causes problems. When users click this link, they get a choice how to open it: always the native browser, and additionally any app that has registered for this kind of link. So if the user has the Twitter app installed, Twitter will be shown as one of the options.
That would be great, except the Twitter app is awful. Most types of suggest-a-tweet URL cause the app to crash, and the few that do work don't pass the status text.
I'm looking for a way to force the URL to be opened by the native browser. (Or way to prevent the Twitter app from being among the options presented to the user, but that seems harder to do)
Is this possible using only the URL itself, or maybe a little Javascript? Since I'm using Titanium, Java won't help me.
I can't give you what you want but give you an alternative suggestion.
What you are trying is hard (often impossible to do without errors) even with native code as your trying to work against the OS. Intents are used in android as a way to let the user decide which program should handle a certain request. If you don't want the user to take this decision I'd suggest opening the url in a embedded browser.
I am thinking of a remote help application where a user needs help navigating a web site.
How can a second user see what the first user is seeing so they can help them over the phone.
Could both users interact with the website?
Is there a solution that will work in any browser that requires no special downloads. I can imagine a simple system where the user browser updates the server with the current location URL but how to see the mouse clicks and dynamic Javascript changes etc.
Edit: This is called "cobrowsing" see wikipedia for a list of solutions
Why not use an existing screen-sharing solution, like http://join.me ?
unblu allows two users to interact with the same website
requires no download
works with Javascript/AJAX etc
works of SSL
can be either cloud or privately hosted
There are others that I have not investigated - you can see a list in the cobrowsing wikipedia page.
I started to work on a very cool Chrome extension and I ran into a little problem.
I want to allow my user to share a link. By sharing this link, other users can get some information with my extension.
The problem is when a user click on the shared link, I want to check if my Chrome extension is installed on his browser. If it does - great, else - I want to redirect him to download my extension.
Any ideas how to?
One possibility is to have your extension run a content script on all sites* and add a listener for click events on document. It would check event.target to make sure it's a link and has a particular prefix, and if it does, it would call the preventDefault method of its parameter and do its stuff. For users without your extension, the link would of course work like any other.
*This causes Chrome to warn your potential users about this when they install your extension; read Permission Warnings for more information.
Make the extension add an invisible element to the DOM of every page that it loads, marking it with a unique ID. When the user clicks on that link, run some javascript to check for that element -- if it doesn't exist, then you know the extension hasn't been installed.
I think you should be able to set/modify headers in the HTTP requests (as of Chrome 17?). Adding a header to requests would mean you can detect the presence of the extension on the server side.
This is fairly unintrusive. Many extensions/plugins have historically modified the User-Agent header.