Skip to content

Instantly share code, notes, and snippets.

@cdeutsch
Last active December 27, 2015 00:59
Show Gist options
  • Select an option

  • Save cdeutsch/7241538 to your computer and use it in GitHub Desktop.

Select an option

Save cdeutsch/7241538 to your computer and use it in GitHub Desktop.
Better Marketo / Salesforce munchkin.js loading that won't fire initMunchkin twice in IE.
<script type="text/javascript">
(function() {
function initMunchkin() {
Munchkin.init('YOUR-ID');
// custom handling after marketo is ready
if (typeof marketo_ready != 'undefined') marketo_ready();
}
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = document.location.protocol + '//munchkin.marketo.net/munchkin.js';
if (s.readyState) { // IE, incl. IE9
s.onreadystatechange = function() {
if (s.readyState == "loaded" || s.readyState == "complete") {
s.onreadystatechange = null;
initMunchkin();
}
};
} else { // Other browsers
s.onload = initMunchkin;
}
( document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0] ).appendChild( s );
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment