Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StartURL Support suggestion #1

Open
PaulKinlan opened this issue Jun 18, 2016 · 4 comments
Open

StartURL Support suggestion #1

PaulKinlan opened this issue Jun 18, 2016 · 4 comments

Comments

@PaulKinlan
Copy link

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:

(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;
            }
          }
        });
      }
    })();
@firtman
Copy link
Owner

firtman commented Jun 23, 2016

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!

@filipbech
Copy link

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 ?

@PaulKinlan
Copy link
Author

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
#1 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AACxxiePXoRroJJ5JdHx7BOUdFzIGza0ks5qOjEbgaJpZM4I5CIt
.

@firtman
Copy link
Owner

firtman commented Jun 23, 2016

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
#1 (comment), 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
#1 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ABQ_Wdg2jmdJp_PZ1KTqBvFsm-4q2cSxks5qOqpAgaJpZM4I5CIt
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants