How to get the baseUrl of Jira from Javascript?

When developing a Connect plugin, in the Javascript of the iframe, I need the host URL. How can I get it?

AP.navigator.getLocation() provides a JSON object, but not the product’s base url,
AP.context.getContext() also provides a JSON object, but not the product’s base url,

Rationale: When some clicks an <a> link,

  • We use AP.navigator.go() so they benefit from internal navigation,
  • Except if they use shift+click, middle-click or ctrl+click, in which cases they want to open in a new window. For those cases, we need to avoid JS navigation, and provide a suitable href value, starting with the product’s base url.

Thank you.
PS: We can’t get the URL from xdm_e because it is deprecated, and AP.getLocation() is not documented anywhere.


If you use ACE, you can put the host URL in your .hbs template in a variable in a tag. (Or similar solution with another stack.)

What @marc says works when you’re rendering stuff in your backend. But if you only have static resources, there’s two ways to do this I’m aware of:

  • AP._hostOrigin (undocumented)
  • Using the data-options="base:true" parameter in the all.js script tag and then picking up the resulting tag from the <head> via javascript:
<base href="https://<instance>" target="_parent">

The second method is documented here. Hope this helps!



The second option (documented) is quite nice, BUT the tag disturbs all relative links on the current page.

I’ll just add:

  • AP.getLocation(callback) (undocumented): It returns the entire current URL of the parent frame. It is different from AP.navigator.getLocation().