Hello Prajakta, if you already have the full URL you can use a "Split" function (splits the full string to an array) and then you can reconstruct your desired string.
You can use an expression widget for this, inside a Mashup (invisible at run time).
You can define whatever trigger you want for the Evaluate service(e.g. Mashup Loaded event) of the Expression, the output of the expression will be a string.
The actual expression to obtain the URL as you mentioned can be : location.protocol+ "//" + location.host + "/Thingworx/"
You can do whatever you want with this output -> use it in a service or display it somewhere. Furthermore, you can also use as an expression: location.href, to obtain the full URL of the Mashup where the user is currently on.
Please let me know if you need more information about this. I hope this was helpful.