Check whether a window is Popup or not?

前端 未结 10 1440
夕颜
夕颜 2020-12-08 20:23

This question is not the duplicate of if window is popup , But a similar one.

I am developing a extension which injects scripts to all web pages. I need to detect w

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 20:29

    I was implementing 'close' button for popup window screen and 'cancel' button for '_self' window in "Typescript/Nodejs" and believe it will work for JavaScript as well. So I needed to determine if screen is opened in a popup

    if(window.opener || window.history.length === 1) 
         isPopupWindow = true;
    else 
       isPopupWindow = false;
    

    "window.opener" works for almost all the browsers but having issue with IE so to handle IE issue I used "window.history.length".

提交回复
热议问题