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

With version 3.2.3, this.container is not defined

Open benlk opened this issue 8 years ago • 5 comments

in ath.Class.prototype, in the function show:

		// attach all elements to the DOM
		this.viewport.appendChild(this.element);
		this.container.appendChild(this.viewport);

this.container is undefined, causing the following error:

addtohomescreen.js?ver=3.2.3:553 Uncaught TypeError: Cannot read property 'appendChild' of null

this.container appears to be defined in the function ath.Class:

// the element the message will be appended to
this.container = document.body;

But the this is not the same, and so this.container is not shared in the context of show()

benlk avatar Nov 28 '16 20:11 benlk

This bug is not appearing in 3.2.2's unminified version, if that helps.

benlk avatar Nov 28 '16 20:11 benlk

Using the unminified version gets rid of the error, but AddToHomescreen never appears. Localstorage is being updated with

org.cubiq.addtohome	{"lastDisplayTime":1480609920899,"returningVisitor":true,"displayCount":1,"optedout":false,"added":false}

gwhenne avatar Dec 01 '16 16:12 gwhenne

Try using window.onload when calling the script. I suspect you're getting the error because document.body is still null when the script is called.

This is what worked for me.

window.onload = function() {
  addToHomescreen();
}

amboy00 avatar Dec 09 '16 16:12 amboy00

If that's the case, then the docs at http://cubiq.org/add-to-home-screen should be updated to put the addToHomescreen(); call in the footer.

benlk avatar Dec 12 '16 22:12 benlk

Had the same issue. Placing <script> addToHomescreen();</script> right after the <body> tag seemed to work.

joshgrift avatar Mar 16 '17 20:03 joshgrift