我想在我的页面标题中添加这样的内容,以便仅在不是iPhone/iPad时加载js和css文件:
if(!(navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)))
{
//Link to js file
//Link to css file
}
Run Code Online (Sandbox Code Playgroud)
第一行工作正常,我通过粘贴脚本来测试它,但我不确定如何将文件链接起来......特别是因为我希望js和css链接以WP模板标签开头 <?php echo get_stylesheet_directory_uri(); ?>
预先感谢您的帮助!
小智 5
<?php
if (!preg_match("{iPhone|iPod}i",$_SERVER['HTTP_USER_AGENT']))
{
echo '<script src="yourscript.js"></script>';
echo '<link href="yourstyle.css" rel="stylesheet" type="text/css">';
}
?>
Run Code Online (Sandbox Code Playgroud)