add-to-homescreen icon indicating copy to clipboard operation
add-to-homescreen copied to clipboard

Method show() crashes first time

Open martindrapeau opened this issue 9 years ago • 4 comments

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

martindrapeau avatar Mar 14 '15 08:03 martindrapeau

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.

cubiq avatar Mar 14 '15 08:03 cubiq

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.

martindrapeau avatar Mar 14 '15 09:03 martindrapeau

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

cubiq avatar Mar 14 '15 09:03 cubiq

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.

martindrapeau avatar Mar 14 '15 11:03 martindrapeau