我已经更改了在页面加载时加载的函数,但它不会这样做。
original code它通过链接运行:
function updateBannerText(text) {
smartsupp('banner:set', 'bubble');
smartsupp('banner:update', { text: text });
});
<a href="javascript:updateBannerText('Welcome')">Welcome</a>,
<a href="javascript:updateBannerText('This chat is awesome')">This chat is awesome</a>
我的代码应该在页面加载时运行:
function updateBannerText(text) {
smartsupp('banner:set', 'bubble');
smartsupp('banner:update', { text: "{$Artikel->cName}" });
}
window.onload = updateBannerText;
我已将 updateBannerText(text)
更改为 updateBannerText()
,但无法运行它。
最佳答案
问题是 Smartsupp 小部件本身仅在页面加载时开始加载,因此您的 window.onload
函数在小部件正确初始化之前运行,因此没有效果。您可以通过延迟横幅更新来测试这一点,这应该会产生效果:
window.onload = function () { setTimeout(updateBannerText, 5000) }
要解决此问题,您应该将启动代码附加到适当的 Smartsupp widget event ,比如说 rendered
event用于更新横幅:
smartsupp('on', 'rendered', function() {
updateBannerText('whatnot')
})
关于javascript - 函数不会在页面加载时运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34961850/