const openInstallPage = () => {
const md = new MobileDetect(navigator.userAgent);
if (md.is("iPhone")) {
window.open(
"https://apps.apple.com/us/app/metamask-blockchain-wallet/id1438144202"
);
} else if (md.os() || md.mobile()) {
try {
window.open(
"https://metamask.app.link/dapp/emirpreview.vercel.app" //deeplink, this url will try to open metamask mobile app. If it cant, i want to redirect user to install page.
);
} catch (err) {
window.open("https://play.google.com/store/apps/details?id=io.metamask");
}
} else {
window.open(
"https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn"
);
}
};
When someone click my button on mobile, i want to redirect user to the metamask app if its installed. If it's not i want to redirect user to metamask install page.
How can i handle this? Try catch methods are not working at all... Am i doing something wrong?
Note: i want to do this things on mobile so im using mobile-deteck package from npm.
Related
I have an issue on azure AD authenticate, I want to make a social sign up form and implement the popup login on that, but when the user success login with social login the popup not close and the callback on the page not execute.
Popup view is a blank view
#{
Layout = null;
}
when it run only have html head and body
the msal script for execute popup
$('.google.btn').click(function (e) {
e.preventDefault();
$.bta.showSpinner();
sessionStorage.clear();
var redirectUrl = '#HttpUtility.UrlDecode(HttpUtility.UrlDecode(Url.Action("SocialSignUpPage", "Account")))';
msalConfig.auth.redirectUri = redirectUrl;
const myMSALObj = new msal.PublicClientApplication(msalConfig);
myMSALObj.loginPopup(loginRequest)
.then((response) => {
console.log(response)
handleAzureResponse(response)
})
.catch(error => {
$.bta.hideSpinner();
if (error.errorCode !== 'user_cancelled') {
$.bta.showErrorDialog(error.errorMessage);
}
});
});
Do anyone know why the popup didn't close and the handleAzureResponse(response) not executed?
Thankyou
Edit: the popup link when stuck https://localhost:44340/Account/SocialSignUpPage#state=eyJpZCI6Im....
Edit 06/02/2023
When I Close the popup, an error appear on my console in app
[c6fd4255-4106-4852-86c1-d0fe60b2ce7f] : msal.js.browser#2.32.2 : Error - PopupHandler.monitorPopupForHash - window closed
I have attached below the mobile app button click, Its perfectly working for Android device, only getting an error: safari cannot open the page because the address is invalid, before being redirected to the redirect URL, can you please anyone help me to resolve the issue
<script type="text/javascript">
function myHref() {
if (navigator.userAgent.match(/iPad/i) || (navigator.userAgent.match(/iPhone/i))) {
document.location = 'app://url2';
setTimeout(function () {
if (confirm('You do not seem to have the app installed. Do you want to go download it now?')) {
location.href = "https://apps.apple.com/";
}
}, 300);
}
if (navigator.userAgent.match(/Android/i)) {
location.href = "https://play.google.com"
}
}
</script>
GET
Website: https://wmiserver.com/dosa-hut
Add to Home Screen feature of google is not working after setting any value in window.location.
What has been done so far?
Refer : web-fundamentals-app-install-banners
During this implementation I am capturing the 'beforeInstallPromptEvent' of window and using it later whenever required.
PFB the Code Snippet for the same:
window.addEventListener('beforeinstallprompt', (e) => {
deferredPrompt = e;
// Update UI notify the user they can add to home screen
showInstallPromotion();
});
btnAdd.addEventListener('click', (e) => {
// hide our user interface that shows our A2HS button
btnAdd.style.display = 'none';
// Show the prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice
.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the A2HS prompt');
} else {
console.log('User dismissed the A2HS prompt');
}
deferredPrompt = null;
});
});
This above code works perfectly in normal journey but it stopworking as soon as I include something in window.location to go to some app which in install in the device,
When the below code for Truecaller functionality is added in tandem with Add to Home Screen, it stops working:
window.location='xxxxxsdk://some-url/';
I have also tried with other options to redirect to app like location.assign() but still same issue.
Hi) try to put it after the app is installed:
window.addEventListener('appinstalled', function() {
// window.location = ...
});
Here is the doc: https://developer.mozilla.org/en-US/docs/Web/API/Window/appinstalled_event
Web push works fine from iframe in local but when i uploaded to cloud server then it does not work in only chrome or chromium browser.
I have developed a webpush micro-service that serve from a Iframe. That works fine in local but when i uploaded to cloud server then it does not work in only chrome or chromium browser. You can check from https:alemran.me (click ^ icon from bot).
Web Worker:
self.addEventListener('push', function (event) {
if (!(self.Notification && self.Notification.permission === 'granted')) {
return;
}
const sendNotification = (title, body ) => {
return self.registration.showNotification(title,
body
);
};
if (event.data) {
const message = JSON.parse(event.data.text());
event.waitUntil(sendNotification(message.title,message.message));
}
});
There is no error show in console
You can open a new window with a url and get permission from user....
Like :
let win = window.open("your url", "_blank");
let winInterval = window.setInterval(function() {
if (win.closed !== false) {
window.clearInterval(winInterval );
//check your api for user subscription status
}
}, 200);
The web page is displayed upon redirection from another website and the URL changes during this process to point to a different port number.
So, I would like the JavaScript to detect if the URL is correct.
If the user closes the browser/tab, display an Alert Box with warning message.
Run PHP script to close the user Session
My code is:
if (window.location.href === "http://abc123.net.au:2048 ") {
$(function () {
try {
opera.setOverrideHistoryNavigationMode('compatible');
history.navigationMode = 'compatible';
}
catch (e) {
}
function OnBeforeUnload() {
$(window).onbeforeunload;
// Post to script that will log the user out
xmlhttp.open("POST", "../logscript.php", true);
xmlhttp.send();
}
function ReturnMessage() {
return "Wait, by closing this session I will end your session. You will be required to log in again t access the site.";
}
function UnBindWindow()
{
$(window).unbind('beforeunload', ReturnMessage);
}
$(window).bind('beforeunload', ReturnMessage);
});
}
else {
document.write('<div>code is not working</div>')
}
This is the solution to your second work order:
window.onbeforeunload = bunload;
function bunload() {
dontleave = "Are you sure you want to leave?";
return dontleave;
}