-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
try { | ||
if (!window.__originalOpen) { | ||
window.__originalOpen = window.open; | ||
window.open = function(url, id, options) { | ||
if (typeof url === 'string' && url.indexOf('javascript') > -1) { | ||
throw new Error('Invalid open window uri'); | ||
} | ||
return window.__originalOpen(url, id, options); | ||
} | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export function popWindow(url: string, id: string, w: number, h: number) { | ||
if (url.indexOf('javascript') > 0) { | ||
throw new Error('Invalid window open url'); | ||
} | ||
// Fixes dual-screen position Most browsers Firefox | ||
const dualScreenLeft = | ||
window.screenLeft !== undefined | ||
? window.screenLeft | ||
: (window.screen as any).left; | ||
const dualScreenTop = | ||
window.screenTop !== undefined | ||
? window.screenTop | ||
: (window.screen as any).top; | ||
|
||
const width = window.screen.width || window.outerWidth; | ||
const height = window.screen.height || window.innerHeight; | ||
const left = width / 2 - w / 2 + dualScreenLeft; | ||
const top = height / 2 - h / 2 + dualScreenTop; | ||
|
||
const newWindow = window.open( | ||
url, | ||
id, | ||
`scrollbars=yes, width=${w}, height=${h}, top=${top}, left=${left}`, | ||
); | ||
|
||
// Puts focus on the newWindow | ||
try { | ||
newWindow?.focus(); | ||
} catch (error) { | ||
/* ignore error */ | ||
} | ||
return newWindow; | ||
} | ||
|
||
export default popWindow; |