js 创建弹出窗口

/**
 * 创建弹出窗口
 * @param url 地址
 * @param winName 窗口名
 * @param width 宽
 * @param height 高
 * @param scrollbars 是否有滚动条
 * @param resizable 是否可调整大小
 */
export function createPopupWindow(
  url: string,
  name: string,
  opts: {
    width: number;
    height: number;
    scrollbars: boolean;
    resizable: boolean;
  }
) {
  const { width, height, scrollbars, resizable } = opts;
  const LeftPosition = screen.width ? (screen.width - width) / 2 : 0;
  const TopPosition = screen.height ? (screen.height - height) / 2 : 0;
  const settings =
    "height=" +
    height +
    ",width=" +
    width +
    ",top=" +
    TopPosition +
    ",left=" +
    LeftPosition +
    ",scrollbars=" +
    (scrollbars ? "yes" : "no") +
    ",resizable=" +
    (resizable ? "yes" : "no");

  return window.open(url, name, settings);
}

示例

createPopupWindow('https://baidu.com','百度',{width: 800, height: 600})

你可能感兴趣的:(JavaScript,【基础】,javascript,前端,html)