window.location.href = /Android|webOS|iPhone|iPad|BlackBerry/i.test(navigator.userAgent) ? "https://www.baidu.com/" : "http://news.baidu.com/";
或
if(/Android|webOS|iPhone|iPad|BlackBerry/i.test(navigator.userAgent)) { window.location.href = "https://www.baidu.com/"; } else { window.location.href = "http://news.baidu.com/"; }