首页>文档>边缘计算>移动端页面跳转

移动端页面跳转

// PC端页面
const PCPage = 'https://www.example.com';
// 移动端页面
const MobilePage = 'https://m.example.com';
async function handleRequest(request) {
    const ua = request.headers.get('user-agent');
    // 如果是移动端,则返回移动端页面
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua)) {
        return await fetch(MobilePage);
    }
    // 如果是PC端,则返回PC端页面
    return await fetch(PCPage);
}
addEventListener('fetch', event => {
    event.respondWith(handleRequest(event.request));
});
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
搜索