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})