add-to-homescreen
add-to-homescreen copied to clipboard
Method show() crashes first time
In method show, we must set the session if it does not exist. Otherwise it crashes.
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.
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.
depends when the code is executed. Have you tried to place it on the onload event?
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.