window.location.href not working in scope application

vai
Kilo Contributor

I want to get current url of the browser in my application, but I see that window.location.href is not working in scope application.. I tried it in both my application scope and global scope catalog items, its working fine in global scope but in my application scope it is not working.

var url = window.location.href;

alert(url);

do we have any alternative for fetching url which works ni scope applications ?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vineeth,



window object doesn't work in scoped app. Here is an alternative.


1) Create ui script in global scope and have function in that which will return window.location


2) call this ui script function from your client side in your scoped app.



It should work



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Jaspal Singh
Mega Patron
Mega Patron

Hi Vineeth,



Could you try using



var url = this.location.href;


alert(url);


vai
Kilo Contributor

this is also not working.


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vineeth,



window object doesn't work in scoped app. Here is an alternative.


1) Create ui script in global scope and have function in that which will return window.location


2) call this ui script function from your client side in your scoped app.



It should work



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,



What is the reason for   - window object doesn't work in scoped app. Here is an alternative.


what is the scope of "window" ??