Given an absolute URL to an item, like:
http://server/sites/mysite/myweb/Lists/MyList/DispForm.aspx?ID=1
or the absolute URL to the item's parent list, like:
http://server/sites/mysite/myweb/Lists/MyList/AllItems.aspx
how can I get the URL of the item's parent web, in JSOM?
(In this case, http://server/sites/mysite/myweb
)
This is in the context of an Item Display Template for a Content Search web part. I know that there is a property you can retrieve from the ctx.CurrentItem
called SPSiteURL
, but that is either the URL of the site collection or the URL of the site that the Content Search webpart is on (they happen to be the same in my case, hence the ambiguity), and I want the URL of the sub-web that the item is on.
What's the best way to do this? I know I can resort to string manipulation (i.e. cut off the item's URL where "/Lists..." starts), but I'd rather do it a better way.
EDIT
Just to be clear, the Content Search web part where this code will be executing is in the root web of the site collection:
http://server/sites/mysite
The item is in a list in a subsite:
http://server/sites/mysite/myweb/Lists/MyList/AllItems.aspx
What I am looking for is the URL of the web where the list that the item comes from is located:
http://server/sites/mysite/myweb
Which in this case is below where the code is executing in the site hierarchy.