You cannot do this without relying on Javascript to dynamically change href. The way in which relative URIs are converted to absolute URIs is described in RFC 3986 Section 5.2.2 :
if defined(R.scheme) then T.scheme = R.scheme; T.authority = R.authority; T.path = remove_dot_segments(R.path); T.query = R.query; else if defined(R.authority) then T.authority = R.authority; T.path = remove_dot_segments(R.path); T.query = R.query; else if (R.path == "") then T.path = Base.path; if defined(R.query) then T.query = R.query; else T.query = Base.query; endif; else if (R.path starts-with "/") then T.path = remove_dot_segments(R.path); else T.path = merge(Base.path, R.path); T.path = remove_dot_segments(T.path); endif; T.query = R.query; endif; T.authority = Base.authority; endif; T.scheme = Base.scheme; endif; T.fragment = R.fragment;
Where R is the relative URL and T is the target.
The above basically says that if the scheme is specified in the relative URI, then the entire uri will be the target uri, so the only way to specify the scheme is to specify the entire URL.
If you want to use the Javascript approach, you can dynamically set href using something like: a.href = 'https://' + window.location.host + a.getAttribute('href') . Where a is your AnchorElement.
Here is a demo of the Javascript version: http://jsfiddle.net/7DWV5/
However, mainly because you encounter it, it is recommended that you store your hostname in the configuration file or discover it from the HTTP Request Host header in the front controller. This way you can simply insert the template into your HTML code when creating the page. This eliminates the need to use client scripts to fix your URLs after they are created, which may be desirable because not everyone has Javascript.
Paulpro
source share