To check External Sharing On or Off for a Site Collection we will use _spPageContextInfo object.
_spPageContextInfo is a global object. It belongs to any pages like site page, wiki, publishing and system pages. It provides us lots of useful information about the web site.
Like
_spPageContextInfo.userId – it gives us a current user id.
_spPageContextInfo.guestsEnabled – It gives us a boolean value for Site Collection external sharing on or off. True means external sharing on. False: means external sharing off.
_spPageContextInfo.isExternalGuestUser – it gives us current user external user or internal user. External user means outside of the current organization.
We cross-check Site Sharing by accessing the Admin Sharing panel, for this we need admin access permission.
References:
Hi Ranjit,
How is it possible to write javascript in sharepoint online. Is this feature removed?
Hello Karishma, In modern view you have to use SpFx and you still add JS in classic SharePoint version using page layout/script editor/site pages, etc. See our other articles for more info.