Only add beforeunload event listener when needed

This is only needed until https://github.com/jamesallardice/Placeholders.js/pull/64 gets merged.