onLoad client script to get current page's URL

Alon Grod
Tera Expert

Hi,

Im trying to get the current page's URL using variables set onLoad client script but Im getting java script error when Im trying to create a Request from the portal and Im not getting alert. How can the current page's URL using client script without getting error?

function onLoad {
var a = window.location.href;
alert(a);

}

  

1 ACCEPTED SOLUTION

Anwesha3
Mega Guru

Hi @Alon Grod ,
Hope you are doing great.
//If user is accessing from portal view
var url = top.location.href;
var value = new URLSearchParams(url).get('sys_id')

 

 

//If user is accessing from catalog view
var gUrl = new GlideURL();
gUrl.setFromCurrent();

Something like this --- 

Anwesha3_0-1701628043717.png



Hope this helps 🙂
Please mark correct if it has resolved or mark helpful if it has contributed in some way to your query.
Thanks, and regards
Anwesha

View solution in original post

3 REPLIES 3

Anwesha3
Mega Guru

Hi @Alon Grod ,
Hope you are doing great.
//If user is accessing from portal view
var url = top.location.href;
var value = new URLSearchParams(url).get('sys_id')

 

 

//If user is accessing from catalog view
var gUrl = new GlideURL();
gUrl.setFromCurrent();

Something like this --- 

Anwesha3_0-1701628043717.png



Hope this helps 🙂
Please mark correct if it has resolved or mark helpful if it has contributed in some way to your query.
Thanks, and regards
Anwesha

-O-
Kilo Patron
Kilo Patron

Where exactly is the Client Script running?

Is it really a Client Script, or is is in fact a Catalog Client Script?

Also why do you want to get the current page's URL?

There might be a better, platform best practice way of achieving the actual requirement (which is it b.t.w.)?