JyLie

vuePress-theme-reco JyLie    2017 - 2023
JyLie

Choose mode

  • dark
  • auto
  • light
主页
分类
  • API
  • HTML
  • css
  • vue
  • Linux
  • Docker
  • Webpack
  • WebGL
  • PixiJS
  • Github
  • BOM
  • XML
  • bug
  • ie
  • uniapp
  • IE
  • mysql
  • font
  • bom
  • canvas
  • video
  • html
  • JavaScript
  • js
  • 运算符
  • RegExp
  • 编码
  • MiniApp
  • nginx
  • Tool
  • node.js
  • cat
  • nodejs
  • protocol
  • URL
  • FLOW
  • DNS
  • Protocol
  • python
  • 安全
  • linux
  • shell
  • IDE
  • Packer
  • ViteJS
  • git
  • vendor
  • WebApp
  • WebView
  • Window API
  • webview
  • 规范
标签
时光轴
GitHub
author-avatar

JyLie

74

Article

79

Tag

主页
分类
  • API
  • HTML
  • css
  • vue
  • Linux
  • Docker
  • Webpack
  • WebGL
  • PixiJS
  • Github
  • BOM
  • XML
  • bug
  • ie
  • uniapp
  • IE
  • mysql
  • font
  • bom
  • canvas
  • video
  • html
  • JavaScript
  • js
  • 运算符
  • RegExp
  • 编码
  • MiniApp
  • nginx
  • Tool
  • node.js
  • cat
  • nodejs
  • protocol
  • URL
  • FLOW
  • DNS
  • Protocol
  • python
  • 安全
  • linux
  • shell
  • IDE
  • Packer
  • ViteJS
  • git
  • vendor
  • WebApp
  • WebView
  • Window API
  • webview
  • 规范
标签
时光轴
GitHub
  • ios 系统使用 window.open() 打开新的页面失效

    • 项目场景
      • 问题描述
        • 原因分析
          • 解决方案

          ios 系统使用 window.open() 打开新的页面失效

          vuePress-theme-reco JyLie    2017 - 2023

          ios 系统使用 window.open() 打开新的页面失效


          JyLie 2022-12-07 iosbug

          持续更新...

          # 项目场景

          兼容 在 ios 系统下的使用 window.open() 打开浏览器。

          # 问题描述

          点击 window.open()失效,点击无效果

          btnAjax.addEventListener("click", function () {
            var onlocal = window.open("", " _blank");
            $.getJSON("https://cnodejs.org/api/v1/topics", function (data) {
              window.open(data.data.url);
            });
          });
          
          1
          2
          3
          4
          5
          6

          # 原因分析

          ios 浏览器的安全策略问题

          由于 window.open() 被广告商滥用,严重影响用户的使用。

          Safari 出于安全机制将 window.open() 的新建页面行为阻挡,阻止了弹出窗口的操作,因此在 Safari 中无法 open 新窗口。

          # 解决方案

          先使用 window.open() 打开个空白页,再通过ajax获取地址,使用其句柄更新其地址

          btnAjax.addEventListener("click", function () {
            var onlocal = window.open("", " _blank");
            $.getJSON("https://cnodejs.org/api/v1/topics", function (data) {
              onlocal.location = "https://www.baidu.com";
            });
          });
          
          1
          2
          3
          4
          5
          6