最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

通过js打开浏览器独立的页面

业界 admin 16浏览 0评论

兼容Chrome浏览器
window.showModalDialog 是IE浏览器特有的内置方法
window.showModalDialog

  let has_showModalDialog = !!window.showModalDialog;
      if(!has_showModalDialog &&!!(window.opener)){
          window.οnbefοreunlοad=function(){
              window.opener.hasOpenWindow = false;
          }
      }
  if(window.showModalDialog == undefined){
      window.showModalDialog = function(url,mixedVar,features){
          if(window.hasOpenWindow){
              window.myNewWindow.focus();
          }
          window.hasOpenWindow = true;
          if(mixedVar) var mixedVar = mixedVar;
          if(features) var features = features.replace(/(dialog)|(px)/ig,"").replace(/;/g,',').replace(/\:/g,"=");
          let left = (window.screen.width - parseInt(features.match(/width[\s]*=[\s]*([\d]+)/i)[1]))/2;
          let top = (window.screen.height - parseInt(features.match(/height[\s]*=[\s]*([\d]+)/i)[1]))/2;
          window.myNewWindow = window.open(url,"_blank",features);
      }
  }
// image.html 为显示的页面
 window.showModalDialog(`/image.html?src=${this.imageUrl}`, '', 'dialogWidth:300px;dialogHeight:380px;');

兼容Chrome浏览器
window.showModalDialog 是IE浏览器特有的内置方法
window.showModalDialog

  let has_showModalDialog = !!window.showModalDialog;
      if(!has_showModalDialog &&!!(window.opener)){
          window.οnbefοreunlοad=function(){
              window.opener.hasOpenWindow = false;
          }
      }
  if(window.showModalDialog == undefined){
      window.showModalDialog = function(url,mixedVar,features){
          if(window.hasOpenWindow){
              window.myNewWindow.focus();
          }
          window.hasOpenWindow = true;
          if(mixedVar) var mixedVar = mixedVar;
          if(features) var features = features.replace(/(dialog)|(px)/ig,"").replace(/;/g,',').replace(/\:/g,"=");
          let left = (window.screen.width - parseInt(features.match(/width[\s]*=[\s]*([\d]+)/i)[1]))/2;
          let top = (window.screen.height - parseInt(features.match(/height[\s]*=[\s]*([\d]+)/i)[1]))/2;
          window.myNewWindow = window.open(url,"_blank",features);
      }
  }
// image.html 为显示的页面
 window.showModalDialog(`/image.html?src=${this.imageUrl}`, '', 'dialogWidth:300px;dialogHeight:380px;');
发布评论

评论列表 (0)

  1. 暂无评论