StartURL Support suggestion
It's really hard to manage the start_url support because clicking a link and going out to browser will. I used msapplication-starturl meta tag to hold the start url, and then I used localStorage and click interception to work out if we would cause an external navigation and if we do I would store that URL in localStorage so the next time the page is loaded it will return from the same place that the user left from (not it should handle subsequent launches from homescreen well too).
context:
- https://gist.github.com/PaulKinlan/d66f777f5bde04926f29fc5c7ff345e7 start-url polyfill
- https://gist.github.com/PaulKinlan/c927188139e8fededda22006c6a42f19 manifest polyfill
(function() {
var startUrlEl = document.querySelector("meta[name=msapplication-starturl]");
if(!!startUrlEl === true && navigator.standalone === true) {
var lastUrl = localStorage["navigate"];
history.pushState({launched: (!!lastUrl == false && history.length === 1)}, undefined, lastUrl || startUrlEl.content);
localStorage.removeItem("navigate");
// Intercept all anchor clicks and keep fullscreen if in origin
document.addEventListener("click", function(e) {
var target = e.target;
if(target.tagName === 'A') {
var href = target.getAttribute("href");
var linkedUrl = new URL(target.href);
if(linkedUrl.origin === location.origin) {
e.preventDefault();
location.href = href;
}
else {
// When we are navigating away store the state so we can resume.
localStorage["navigate"] = location.href;
}
}
});
}
})();
Hi @PaulKinlan; thanks for the suggestion but I didn't quite get it. I didn't get the localStorage thing as the problem is that the contexts in Safari and Web.app are different -no localStorage sharing as far as I understand. Therefore, I understand the only solution is through URL, that's the only thing that Web.app will get from the browser. Am I missing something? Thanks!
If I understand it correctly you are right that localstorage is NOT shared between browser running the site and running it from homescreen. However what I think Pauls code is doing is just for handling when you are clicking around inside the "homescreened" version, and the localstorage thing is for when you click an external link and then later return to the homescreened version (so you "stay where you are" instead of going to the start-url... But I might be mission something too... @PaulKinlan ?
Filip is correct, it is just for the added to honescreen experience. If you navigate out of the "app" in to a new window and then press back you would normally be sent back to the launched URL and not the pushState URL. This shim just solves that by storing what the last URL was when exiting the app. It is also used to differentiate when it is a launch from homescreen vs re-navigate back into app.
On Thu, 23 Jun 2016, 08:09 Filip Bech-Larsen, [email protected] wrote:
If I understand it correctly you are right that localstorage is NOT shared between browser running the site and running it from homescreen. However what I think Pauls code is doing is just for handling when you are clicking around inside the "homescreened" version, and the localstorage thing is for when you click an external link and then later return to the homescreened version (so you "stay where you are" instead of going to the start-url... But I might be mission something too... @PaulKinlan https://github.com/PaulKinlan ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firtman/iWAM/issues/1#issuecomment-227967971, or mute the thread https://github.com/notifications/unsubscribe/AACxxiePXoRroJJ5JdHx7BOUdFzIGza0ks5qOjEbgaJpZM4I5CIt .
OK. That behavior was in my Todo list 😀 in my case I'm using the url and start_url for other purpose. For example if you are in a product at flipkart I want the webapp to start from scratch not to load that particular product. That's what I'm doing with the code when start_url doesn't match current url. On Thu, Jun 23, 2016 at 17:46 Paul Kinlan [email protected] wrote:
Filip is correct, it is just for the added to honescreen experience. If you navigate out of the "app" in to a new window and then press back you would normally be sent back to the launched URL and not the pushState URL. This shim just solves that by storing what the last URL was when exiting the app. It is also used to differentiate when it is a launch from homescreen vs re-navigate back into app.
On Thu, 23 Jun 2016, 08:09 Filip Bech-Larsen, [email protected] wrote:
If I understand it correctly you are right that localstorage is NOT shared between browser running the site and running it from homescreen. However what I think Pauls code is doing is just for handling when you are clicking around inside the "homescreened" version, and the localstorage thing is for when you click an external link and then later return to the homescreened version (so you "stay where you are" instead of going to the start-url... But I might be mission something too... @PaulKinlan https://github.com/PaulKinlan ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firtman/iWAM/issues/1#issuecomment-227967971, or mute the thread < https://github.com/notifications/unsubscribe/AACxxiePXoRroJJ5JdHx7BOUdFzIGza0ks5qOjEbgaJpZM4I5CIt
.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/firtman/iWAM/issues/1#issuecomment-228093337, or mute the thread https://github.com/notifications/unsubscribe/ABQ_Wdg2jmdJp_PZ1KTqBvFsm-4q2cSxks5qOqpAgaJpZM4I5CIt .