Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

Method show() crashes first time #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

martindrapeau
Copy link

In method show, we must set the session if it does not exist. Otherwise it crashes.

@cubiq
Copy link
Owner

cubiq commented Mar 14, 2015

you are probably calling the method too soon, I don't think it's a good idea to force the default session. it would be better to check the session and eventually return false.

@martindrapeau
Copy link
Author

I used your example:

var addtohome = addToHomescreen({
   autostart: false
});
addtohome.show();

However I loaded the JS file dynamically. So maybe you don't handle that properly.

@cubiq
Copy link
Owner

cubiq commented Mar 14, 2015

depends when the code is executed. Have you tried to place it on the onload event?

@martindrapeau
Copy link
Author

Here's the exact code:

function loadScript(url, callback) {
  var head = document.getElementsByTagName("head")[0];
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = url;
  if (callback) {
    script.onreadystatechange = callback;
    script.onload = callback;
  }
  head.appendChild(script);
}

loadScript("add-to-homescreen/src/addtohomescreen.js", function() {
  var addtohome = addToHomescreen({
    autostart: false
  });
  addtohome.show();
});

Very useful plugin by the way.

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

Successfully merging this pull request may close these issues.

2 participants