振动API在页面加载中不起作用 [英] Vibrate API not working on pageload
本文介绍了振动API在页面加载中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码不起作用...
The following code isn't working...
function onPageLoad(){
navigator.vibrate([500]);}
在移动设备上对其进行测试,当我将其连接到按钮时可以正常工作但无法加载吗??
Testing it on mobile device, when I attach to a button it works but not onload????
推荐答案
如果要执行任何javascript代码,则需要将其写入javascript onload
方法
IF you want to execute any javascript code you need to write it to javascript onload
method
window.onload = function() {
navigator.vibrate([500]);
};
或者您可以将函数附加到body元素的onload事件上,
or you can attach your function to body element onload event,
<body onload="onPageLoad()">
这篇关于振动API在页面加载中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文