I'm trying to open my mobile application using javascript inside iframe. It works fine in most of devices ( Android web browsers, iPhone firefox, iPhone Edge ) but doesn't work in iPhone Safari browser.
These are the codes that I've tried.
function openApp(){
document.location = "myapp://someUrl"; // opening my app
}
function openAppTry2(){
location.href = "myapp://someUrl"; // opening my app
}
It works fine if it's not in iframe , but has no reponse when the function is called from inside iframe.
I took reference from these posts but still couldn't use app link inside iframe.
https://developer.apple.com/forums/thread/19928
How to make iOS universal links work inside an iframe
Instead, I found other way to solve this problem using applink outside iframe.
Using window.addEventListener allows scripts inside iframe to call function that locates outside iframe.
window.addEventListener("message", callback, false); // init outside iframe
...
function callback (event) {
useData(event.data);
document.location = "myapp://someUrl"; // opening my app
}
and then use window.parent.postMessage to send datas to outside of iframe and call functions
window.addEventListener("message", setMessage, false); // init inside iframe
...
window.parent.postMessage(datas); // send data to caller of iframe