0

I'm in the process of building a new website for my wife's business, using Squarespace. Don't tell her, since it's one of her Christmas presents. :)

However, I'm experiencing a weird issue. About half of the pages on the site include content from a third-party widget called Healcode. Those pages have a strange jerkiness to them on pageload, where the logo and navbar move around -- ultimately winding up in the right spot, but looking bad while doing so. Pages that don't have a third-party widget don't have this jerkiness.

Example of page that jerks: https://coconditioning.squarespace.com/yoga-classes/
Example of page that doesn't jerk: https://coconditioning.squarespace.com/private-coaching/

The Healcode widget is javascript code that looks like this:

<script type="text/javascript">
  healcode_widget_id = "ay12237c4nc";
  healcode_widget_name = "schedules";
  healcode_widget_type = "mb";
  document.write(unescape("%3Cscript src='https://www.healcode.com/javascripts/hc_widget.js' type='text/javascript'%3E%3C/script%3E"));
  // Healcode Schedule Widget for Conscious Conditioning L.L.C. : Weekly Schedule New
</script>
<noscript>Please enable Javascript in order to get <a href="https://www.healcode.com" target="_blank">HealCode</a> functionality</noscript>

Any help would be MUCH appreciated. Thank you in advance!

4

2 回答 2

0

如果可能,不要尝试使用 document.write,因为 document.write JS 解析器不知道放在哪里。充其量,浏览器会忽略它。在最坏的情况下,它可能会覆盖您当前文档的顶部。利用appendChild

function loadHealCodeScript () {

    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'https://www.healcode.com/javascripts/hc_widget.js' 
    document.body.appendChild(script);

}

window.onload = loadHealCodeScript; // load healcode after page has been loaded

抖动效应正在发生,因为修复代码在页面完全加载之前加载其脚本。如果可能的话,把你所有的javascript放在body标签之后而不是head之后

正如谷歌所建议的那样https://developers.google.com/maps/documentation/javascript/tutorial?hl=en#asynch

于 2013-12-23T02:04:51.447 回答
0

您可以隐藏页面直到body加载:

<body style = 'display: none'; />

在您的 javascript 中,添加window.onload()

healcode_widget_id = "ay12237c4nc";
  healcode_widget_name = "schedules";
  healcode_widget_type = "mb";
  document.write( unescape("%3Cscript src='https://www.healcode.com/javascripts/hc_widget.js' type='text/javascript'%3E%3C/script%3E"));
  // Healcode Schedule Widget for Conscious Conditioning L.L.C. : Weekly Schedule New

window.onload = function()
 {
   document.body.style.display = 'block';
 };

另外,对您来说是document.write()最好的解决方案吗?

于 2013-12-23T02:00:06.113 回答