博客
关于我
window.open 防止浏览器拦截
阅读量:582 次
发布时间:2019-03-11

本文共 605 字,大约阅读时间需要 2 分钟。

通过多次尝试,发现直接使用JavaScript控制页面重定向存在一定的挑战性。以下是实现成功的具体方法和优化建议:

实现方法:

var newWin = window.open('https://www.baidu.com/');wxPublic().then(function() {    if (res.data.statusCode !== '200') {        newWin.location.href = '404页面';        return;    }    newWin.location.href = res.data.responseContent.url;}).catch(function() {    newWin.location.href = '404页面';    // 可以选择关闭新窗口:newWin.close();});

优化建议:

  • 快速响应机制:为了避免因接口响应速度过慢导致页面长时间停留,可以在请求开始前,先打开一个占位页面。例如:
  • window.open('loading.html');
    1. 失败处理机制:如果接口响应异常或页面加载失败,可以采取以下措施:
      • 重定向到404页面。
      • 关闭不必要的新窗口。
    2. 资源优化:确保加载的页面资源尽可能轻量化,减少因资源加载时间过长导致的页面停留。
    3. 通过以上方法,可以有效提升页面加载速度,确保用户体验不受影响。

    转载地址:http://pcptz.baihongyu.com/

    你可能感兴趣的文章
    python selenium自动化测试报告
    查看>>
    Python selenium自动化测试框架实战 —— 登录测试案例
    查看>>
    Python Selenium设计模式 —— POM
    查看>>
    Python Serial:如何使用 read 或 readline 函数一次读取多个字符
    查看>>
    Python set([]) 如何检查两个对象是否相等?一个对象需要定义哪些方法来自定义它?
    查看>>
    Python setup.py:数据文件无法复制目录:不存在或不是常规文件
    查看>>
    Python setuptools sdist:仅安装版本化文件
    查看>>
    Python Shell下使用matplotlib
    查看>>
    Python Slice How-to,我知道Python Slice,但我怎么才能使用内置的Slice对象呢?
    查看>>
    python socket分包发送数据
    查看>>
    python socket模块_Python socket模块实现TCP服务端客户端
    查看>>
    Python SOCKS5代理客户端HTTPS
    查看>>
    Python Soc网络分析:通过使用函数迭代列表来计算机会网络
    查看>>
    Python SQL和NoSQL数据库操作实战
    查看>>
    python stdout flush_sys.stdout.flush()方法的用法
    查看>>
    python string 运算
    查看>>
    Python str与bytes之间的转换
    查看>>
    Python subprocess ffmpeg
    查看>>
    python subprocess Permission denied Errno 13
    查看>>
    Python subprocess.call - 将变量添加到 subprocess.call
    查看>>