Instagram has some cool hooks that can be used to open the app from a web url.
e.g. instagram://camera
But when a user doesn't have instagram installed, the browser doesn't know how to handle the url. Is there a way for me to detect if the user has instagram installed (in javascript)?
In Objective-C the [[UIApplication sharedApplication] canOpenURL:url] expression may be used to detect whether a URL is handled by any app in the system. If you use PhoneGap or some similar framework, then look for this method. If you have only a webapp, then I'm pretty sure that this is impossible.
The issue with a web app is that it is sandboxed like a web page, it cannot reach outside of the browser. However, it seems to be possible that you can detect the presence with a timing based method. That is, if the app is not installed, the user will return to, or not be able to leave at all the browser within a certain, relatively short time. Thinking along these lines I found this solution: Check if URL scheme is supported in javascript
You may be able to build a solution using this approach, but the "Cannot Open Page" alert box will always be thrown at your users. Though, this IMHO is not really annoying if you handle it correctly on the web app side.
UIApplication has a method canOpenURL: that you can use to check.
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"instagram://camera"]]) {
}
Related
I'm currently developing a web app that allows users to add a list of websites that they want to block i.e. preventing them from accessing the website from their browser.
Ideally I want to be able to block websites on every browser but this is difficult, so I narrowed my research to just Chrome for now. I came across the chrome.webRequest api which seems promising but it specifically says its for chrome extensions and am unsure if it would work for my web app.
Can anyone point me in the right direction for blocking websites on a web app, ideally using javascript. Any help is much appreciated!!
EDIT:
1) I forgot to mention that I'm using firebase for my backend.
2) People have been saying that I can't block websites outside the web apps scope, if I instead used electron to make the web app a desktop application would it then be possible?
Firstly you have a database containing URL of blocked websites. URLs are modified using your web app. That's one part. Now your problem is how to make the browser work with your database.
The only possible way for you to share blocked URLs with the browser is via API. You must have API that can communicate outside your web app.
Now browsers such as chrome/firefox give users the power to make changes inside and outside the dom. For chrome, you have chrome extension where Google provides API so the users can manipulate actions outsides regular actions such as manipulating dom. An example I can give that is closely related to your subject matter, which is an action activated before/after a user enters URL on the search box and for that, we use the following API from https://developer.chrome.com/extensions/webRequest
And it's same for Firefox.
Most of the people who will access my app will do so from a preinstalled software on their pc that has a browser component built with Microsoft's WebBrowser Control which is just Internet Explorer wrapper.
I want to know if there's a way I can detect, using Javascript, or any other method from inside my website, when it is being rended using this wrapper.
The reason I want to do this is that software was already built and goes to the home page of my site. But I want to redirect them directly to the login screen if they are accessing from that wrapper.
By default the WebBrowser Control uses IE7 so you can check the user agent string (I doubt your other users will be using such an old Internet Explorer version as their browser causing a faulty recognition).
However, this is not a perfect solution, if you can modify the preinstalled software and deliver a new version to people that will be using it you can send a specific header along with the request to determine its origin.
I don't think you can do this accurately. As Samuil stated, you can hack it a bit and maybe catch some of it.
Why not set the default page of your website to be the login page so the user goes to that page regardless?
I want to detect via JS if a user does or does not have a particular app installed.
I know about the app store tag that will pop the generic "download this app" if they don't have it installed. I'm not asking about that.
I have a concept, but it's incomplete. This would try to target both iPhone and Android devices.
Knowing that a link with a particular prefix can trigger an app to open:
Target a hidden iframe with JS to open a url prefixed to trigger that app
That page would fire a post message back to the parent if it loads, indicating the app was not opened.
If the app exists, the message would never be fired back to the parent, since it would open in the app.
Unfortunately, my client does not want app to open (or attempt to open) automatically, but simply know wether or not it's installed.
Thoughts? Blaring errors in my logic? Work-arounds? Existing solutions?
Thanks
There's likely no way to do this, because generally speaking you aren't allowed to poke around on a user's device from a web page. Even though what apps a user does or doesn't have installed isn't the most sensitive of personal information, it would still be a bit of a security/privacy concern to expose that information to scripts coming from the web. The app store tag is probably the closest you're going to get, since it's an official API to provide similar but protected functionality.
I can think of two ways to try to solve your problem, although none is especially good. Since iOS 6, you can use Smart App Banners to promote an app.
The most obvious solution would be to hide any actions from the user, e.g. by preventing the activity from showing up after issuing the URL request. I don't have any experience with this and cannot tell you to what extent it might be possible to hide it.
To be honest, I have no idea whether the second approach will work on mobile devices. It has been used for desktop applications a lot and allows inter-application communication - including communication between the browser and the app. However, the possibilities might be limited due to the usually high security restrictions on mobile devices. This is a highly theoretical suggestion as I am pretty sure it is unsuitable, whether it is possible or not.
Your app must provide a tiny HTTP server on an unused but fixed port. Your JavaScript code can then use JSONP to communicate with the app (assuming the security restrictions of the browser don't prevent this). If communication fails, you may assume the app is not installed.
Before anyone attempts to criticize this approach, let me say that this is a theoretical possibility, might be unstable and is unsuitable for most apps. The efforts of running an HTTP server are far too high for such a secondary task.
I have a webpage that is being viewed from a webview in a native app, this webpage has a element. The file input works fine in the web browser but does not work in the app (different problems on both iPhone and Android).
The app has already been published and I would really not like to update the native portion of the app.
The ideal solution would be to add java-script to the webpage that can detect that it is running inside the app and then launch a browser (outside of the app) with the URL.
Is this possible somehow?
It's possible if your app overrides default user agent used by webview. By default the user agent for webview is same as that of default browser. So you don't have any way to differentiate those. If your app overrides useragent, then you can sniff useragent using javascript & take action based on that. Ideal solution will be to try to fix the problem with your html though.
My understanding is that it's impossible to launch the browser which is outside of the app without changing the app.
You may add a code like below in iOS.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *address = request.URL.absoluteString;
if( address is needed to be launched on the webbrowser ) {
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
return YES;
}
It's recommanded to define a protocol between the webpage and the app. Cheers.
Launching a browser should be no problem, as posted here:
Can I launch an intent using only javascript in an Android browser?
However, detecting the app is tough. If you are already using a javascript bridge in the app, then you can make a call to the native app javascript bridge and if it succeeds, then you know you are in "your app" and can respond with the intent call above.
Failing that, user agent detection, as mentioned elsewhere, may be your best option.
In other words, you need an identifiable and unique action within the webview in order to have confidence that you are actually in it. If you did a plain vanilla implementation, then you will be forced into either having user interaction ("If you are using our app, click here" - horrible!) or updating the native app.
Synopsis: I am developing a HTML5 web app that will allow tablets(iPad or Droid) to login to a server and perform various functions. The client would like a way to check the devices mac address when logging in. From what I have read, most solutions use activex objects that will not work for webkit browsers.
Question: Does anyone know a solution that would hook into a HTML5 web app seamlessly(Idealy update a hidden form element with the value upon logging in)?
Thanks!
I don't think there's going to be a straightforward way to do this. The web server won't be exposed to a client's MAC address unless they're on the same physical segment...you'll only see the MAC from the most recent router hop in general.
If anything exists, it's going to be a browser plugin (show-stopper on iOS). And it would probably need more than the default permissions available (I don't suspect you can enumerate network interfaces in Java, for example, without asking for elevated permissions).
If you're looking for HTML/JS only then I don't think that this is possible. It won't be exposed.
The problem is that the packets you recieve back will only contain the MAC address of the node on the last hop.
This may be possible via a plugin, but then this limits you on iOS, and possibly also Android as you'd need to provide them a way of getting the plugin first (unless you used a plugin that was installed by default).
Edit: Not that I support an app for every little thing, but it shows that easy to press app buttons sometimes tend to do better than web apps (regardless of being able to make browser shortcuts to home screens). If it is suitable, you could consider loading this within a web view on the target device from within an app, from which you can then of course access MAC addresses and whatever else you may need.
MobiThinking: Mobile applications: native v Web apps – what are the pros and cons?
Forbes: Mobile Web App vs. Native App? It's Complicated