Detecting custom url protocol handler using javascript in windows 10 Edge Browser - javascript

In our web application we need to find out if a Custom URL Protocol Handler is registered or not in windows 10 machine using javascript with Windows 10 EDGE Browser.
If the Custom URL Protocol Handler is not registered in the windows 10 machine we will ask the user to download our desktop standalone app.
If registered we will start our desktop standalone app using the registered Custom URL Protocol Handler.
Since EDGE is a new browser the solutions provided by other users in the internet are not working.
Links I referred that are not working for me in EDGE browser:
https://gist.github.com/keyvanfatehi/f2f521c654bab106fdf9
Please help me out,
Thank you

Maybe this workaround helps:
Whenever you navigate to an unkown protocol with MS Edge, Windows asks the user about the app to handle this protocol. You could just navigate to your protocol and display a message with some information about what to do if the tool does not open. Something like this (sorry for the German screenshot):
<div id="toolBox">
<p id="toolBoxText"></p>
<input type="button" id="toolButton" onclick="openTool()" value="Start tool" />
</div>
<script type="text/javascript">
function openTool(){
window.location = 'myprotocol://command/';
document.getElementById("toolButton").value = "Try again";
document.getElementById("toolBoxText").innerHTML = "Thank you for using our tool. If the tool did not open successfully, please first download and install the tool <a href='download/'>here</a> and then try again."
}
</script>

Related

When using facebook deep URL to open app, both app and webpage open together

I am using this as my link in webpage.
<a class="btn btn-lg btn-orange" role="button" onclick="myFunction()">like me</a>
And this as my script.
function myFunction() {
$(function(){
window.location = "fb://profile/1456471431314551";
setTimeout(function () { window.location = "https://www.facebook.com/angelsatwork2015"; }, 25);
})
}
When I open in mobile both the browser fb page and the fb app open. Please help so that if the app opens it does not redirect to fb browser page.
Also when I use this code on desktop two different browser pages open.
This is most likely the expected behavior for that code.
What you're doing when that button is clicked is immediately opening the URL fb://profile/1456471431314551. Assuming this is iOS, this causes the system to show an alert asking if you want the app to launch. However, as of iOS 9.2, this alert is non-blocking, which means other code continues to execute in the background. This is why, 25 milliseconds later, you're opening the URL https://www.facebook.com/angelsatwork2015 as a regular webpage.
Unfortunately there is no good solution to this in the iOS 9.2+ world (thanks, Apple...). What we do at Branch.io is a combination of Universal Links (which launch the app when it is installed...most of the time) and redirections like the one you're trying for edge cases where Universal Links don't work. We set tracking cookies based on device UUID to know when we are safe to attempt launching the app, but in reality, this often means we have to redirect to the App Store if we aren't sure, just to avoid the behavior you're encountering.

javascript open link in external program instead browser

is there any way to use javascript to open a link in an external program and not(!) in the web browser?
Background: From CRM2015 on-premise i want to open a Mail in Lotus Notes.
script:
<html>
<body>
<p onclick="myFunction()">Click me</p>
<script>
function myFunction() {
window.open("notes:///server/file");
}
</script>
</body>
</html>
What happens: the mail opens in Lotus Notes -> good
But also an additional tab in IE11 occurs, blank page and link in address bar -> bad
What should happen: mail will open in Lotus Notes but no additional tab or windows in IE11.
Is there any way to solve my issue?
Thanks a lot for you help and have a great weekend!
If you want to navigate to an external protocol via JS, do it the same way you'd navigate to a HTTP URL:
function goSomewhere() {
window.location = "notes:///server/file";
}
Sane browsers should 1. stay on the same page, and 2. launch the external program (emphasis on should and no guarantees on insane browsers - e.g. IE8 and below).

Chrome 49 not launching custom url scheme and mailto within chrome extension

I have an extension within which there is a page which contain a button to launch custom url scheme :
errorpage.html
<form>
<button class="button" formaction="myextension://" id = "start_app">Open My App</button>
</form>
Also I have a mailto link on that page :
Send Mail
They both were working fine before i updated chrome to version 49 from version 48.I don't know wether there is some change in permissions or it is a bug in chrome.
For testing purpose i created a seperate html page outside chrome extension and put above links into it and it is working fine.So i think there may be some change in chrome extension api to support mailto and custom url scheme protocol.
Any solutions.

Deeplinking mobile browsers to native app - Issues with Chrome when app isn't installed

I have a webpage, lets call it entry.html.
When a user enters this page, a javascript code (see below) is attempting to deep-link the user to the native iOS / Android app.
If the deep-link fails (probably if the app isn't installed on device), user should "fall back" to another page- lets call it fallback.html.
here is the javascript code that is running on entry.html:
$(function(){
window.location = 'myapp://';
setTimeout(function(){
window.location = 'fallback.html';
}, 500);
});
this is a standard deep-linking method that is recommended all over the network; try to deep-link, and if the timeout fires it means that deep-link didn't occur- so fallback.
this works fine, as long app is installed on device.
but if the app isn't installed, this is the behaviour when trying to deep-link:
Mobile Safari: I see an alert message saying "Safari cannot open this page..." for a moment, and then it falls-back properly to fallback.html- which is the expected behaviour.
Mobile Chrome is my problem.
when the app isn't installed, browser is actually redirected to the myapp:// url, which is of course, invalid- so i get a "not found" page, and fall-back doesn't occur.
Finally- my question is:
How can I fix my code so FALL-BACK WILL OCCUR on mobile Chrome as well? just like mobile Safari?
note: i see that LinkedIn mobile website does this properly, with Safari & Chrome, with or without the app installed, but i couldn't trace the code responsible for it :(
note2: i tried appending an iframe instead of window.location = url, this works only on Safari, mobile Chrome doesn't deep-link when appending an iFrame even if app is installed.
Thanks all!
UPDATE:
i found a decent solution, and answered my own question. see accepted answer for my solution.
for whoever is interested, i managed to find a decent solution to solve these issues with deeplinking Chrome on Android.
i abandoned the myapp:// approach, i left it functioning only in cases of an iOS device.
for Android devices, i'm now using intents which are conceptually different than the myapp:// protocol.
I'm mainly a web developer, not an Android developer, so it took me some time to understand the concept, but it's quite simple. i'll try to explain and demonstrate MY solution here (note that there are other approaches that could be implemented with intents, but this one worked for me perfectly).
here is the relevant part in the Android app manifest, registering the intent rules (note the android:scheme="http" - we'll talk about it shortly):
<receiver android:name=".DeepLinkReceiver">
<intent-filter >
<data android:scheme="http" android:host="www.myapp.com" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>
now, after this is declared in the app manifest, i'm sending myself an email with "http://www.myapp.com" in the message.
when link is tapped with the Android device, a "chooser" dialog comes up, asking with which application i want to open the following? [chrome, myapp]
the reason this dialog came up upon tapping on a "regular" url, is because we registered the intent with the http scheme.
with this approach, the deeplink isn't even handled in the webpage, it's handled by the device itself, when tapping a matching link to an existing intent rule defined in the Android app manifest.
and yes, as i said, this approach is different by concept than the iOS approach, which invokes the deeplink from within the webpage, but it solves the problem, and it does the magic.
Note: when app isn't installed, no chooser dialog will come up, you'll just get navigated to the actual web page with the given address (unless you have more than 1 browser, so you'll need to choose one... but lets not be petty).
i really hope that this could help someone who's facing the same thing.. wish i had such an explanation ;-)
cheers.
It is very important to make sure that when you try to open a deeplink URL with JavaScript that the URL is properly formatted for the device and browser. (If you do not use the appropriate deeplink URL for the browser/platform, a user may be redirected to a “Page Not Found”, which is what you experience.)
Now you must note that Chrome on Android has a different URL format than the old standard Android browser 1! You need to annotate the deep links using href="android-app://" in the HTML markup of your web pages. You can do this in the section for each web page by adding a tag and specifying the deep link as an alternate URI.
For example, the following HTML snippet shows how you might specify the corresponding deep link in a web page that has the URL example://gizmos.
<html>
<head>
<link rel="alternate"
href="android-app://com.example.android/example/gizmos" />
...
</head>
<body> ... </body>
For more details, see the references here:
https://developer.chrome.com/multidevice/android/intents
https://developers.google.com/app-indexing/webmasters/server
https://developer.android.com/training/app-indexing/enabling-app-indexing.html#webpages
And here's a deep link testing tool for Android: https://developers.google.com/app-indexing/webmasters/test.html
Hope that helps.
1 Since the old AOSP browser was replaced by chromium, this is now the default way to handle deep links for recent Android versions. Nonetheless, Android still requires a conditional soltion, because older OS versions still use the AOSP browser.
I have created a Javascript plugin, which supports most of the modern browsers on mobile. But it requires to have deep linking landing pages to be hosted on cross domain(different than universal link url) to work on ios9 Facebook using universal linking. There is also different way to get that working on the Facebook iOS9 using Facebook SDK. I am sharing this if anyone might find this helpful. Currently it does not fallback option, but if falls back to the App Store.
https://github.com/prabeengiri/DeepLinkingToNativeApp
I am Using this Code to for deeplinking.
If the app is installed the app will open up..
If the app is not installed then this remains as it is..
If you wish to add any other condition for app no install then just uncomment the setTimeout code .
<script>
var deeplinking_url = scootsy://vendor/1;
$(document).ready(function(){
call_me_new(deeplinking_url);
});
var call_me_new = function(deeplinking_url){
if(deeplinking_url!=''){
var fallbackUrl ='http://scootsy.com/';
var iframe = document.createElement("iframe");
var nativeSchemaUrl = deeplinking_url;
console.log(nativeSchemaUrl);
iframe.id = "app_call_frame";
iframe.style.border = "none";
iframe.style.width = "1px";
iframe.style.height = "1px";
iframe.onload = function () {
document.location = nativeSchemaUrl;
};
iframe.src = nativeSchemaUrl; //iOS app schema url
window.onload = function(){
document.body.appendChild(iframe);
}
//IF the App is not install then it will remain on the same page.If you wish to send the use to other page then uncomment the below code and send a time interval for the redirect.
/*
setTimeout(function(){
console.log('Iframe Removed...');
document.getElementById("app_call_frame").remove();
window.location = fallbackUrl; //fallback url
},5000);*/
}
};
</script>
setTimeout(function () { if (document.hasFocus()) { window.location = 'URL WILL BEHERE';} }, 2000);
window.location = 'app://';
Need to check document.hasFocus() here because if app is open then playstore url is also open in browser
I also had similar issue, there is a possible alternative for this. If the app is not installed on user's device we can redirect that to some other url.To know more about it Check Here
Example:
Take a QR code
In my case its working fine in opera and chrome browser my deeplink url is
"intent://contentUrl + #Intent;scheme=" +envHost +;package="+envHost+";end";
For other browser create iframe and append the url.
Note -: iframe url append having issue with old device and in firefox its opening app dialog .

How can I open a Windows Explorer window from JavaScript?

I own a local PHP point of Sale, using wampp as my web-server (Win7). What I'm looking for is to find a way to open the Flash Drive E as we normally do by visiting My Computer - > USB Flash E: ... but using JavaScript.
I have found this code, which works perfectly as needed... But this only works on IE, I'm using Google Chrome as my POS browser but what Chrome does... Opens up a blank window!
Here is the code:
<script>
function CallMe()
{
window.open("file://PCNAME/E$");
}
</script>
<html>
<input type="button" onClick="CallMe()" value="Open USB" />
</html>
Is there an alternative way to open USB Drive E? Maybe by using PHP?
You could allow the user to navigate their filesystem from the browser using:
<input type="file" />​
You can't specify a default location nor can the browser open it automatically, however.
window.open("file:///" + yourLocalOrNetworkPath);

Categories