what is the difference between window.open() and $window.open() methods.

Ram118
Mega Guru

I see some of the widgets are using $window.open() and others are using $window.open().

Similarly, some are using window.postMessage() and others are using $window.postMessage().

Is there any difference between them like with/without "$" symbol infront of it. ??

Please let me know if you have any information.

5 REPLIES 5

Sebastian L
Mega Sage

There is a great explanation here: https://docs.angularjs.org/api/ng/service/$window 

 

In general, always use $window in widgets and remember to inject it to the controller 🙂 


Best regards,
Sebastian Laursen

Hi Laursen,

Yes, I have checked this article about $window already. 

In my scenario, I have to replace the usage of window objects with the Angular services in the widgets.

If I do that, will there be any difference in the usage or performance ? This I want to know.

Hello @Ram118, did you get to know on the difference in usage/performance? Also, did you replace window with $window eventually?

Harish Bainsla
Kilo Patron
Kilo Patron
  1. $window.open() vs. window.open():

    • $window.open() is a ServiceNow-specific method provided by the GlideWindow API. It's used to open new windows or dialogs within the ServiceNow platform, providing additional control and customization options.
    • window.open() is the standard browser JavaScript method used to open new browser windows or tabs. It's not specific to ServiceNow and can be used in any web context.
  2. $window.postMessage() vs. window.postMessage():

    • $window.postMessage() is a ServiceNow-specific method provided by the GlideDialogWindow API. It's used to send messages between a parent window and a child dialog or iframe window within the ServiceNow interface.
    • window.postMessage() is the standard browser JavaScript method used to safely enable cross-origin communication between Window objects; it's often used to communicate between different tabs or frames in a web application, regardless of the platform.