Link to home
Start Free TrialLog in
Avatar of bmsande
bmsande

asked on

How do I pull the base url for use in html links

I have an application that has a plugin for some custom html/javascript to help customize the main landing page.  The main landing page has static links that link to other pages within the application.   However, depending on how the user accesses the application, there is a different base url (virtual dir).  

example base urs:

https://external.application.xyz/sso/app.exe
https://internal.application.xyz/app/app.exe

example links:

https://external.application.xyz/sso/app.exe/open/1234
https://internal.application.xyz/app/app.exe/open/1234

So how to I update the html links to include the variable virtual directory.  Right now i'm just using a hardcoded "/app.exe/open" but we recently added /sso so customers are getting redirected to the wrong instance when they click a link.
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

I don't understand the question.

What is in the rendered HTML?

Why don't you render the HTML with the correct links?

If you have to amend the links - then what rules do you use to know what to append to the links?
Are you using a server-side backend language (ASP.Net, PHP)?  If so, you could look at the URL and update the links accordingly.

If you're not using a server-side language, you could probably do the same thing on the client using javascript.
Use window.location.href and differentiate between https://external.application.xyz and https://internal.application.xyz

 var currentURL = window.location.href;
 
 if (currentURL.startsWith('https://external.application.xyz'))
 {
     //https://external.application.xyz
 }
 else
 {
     //https://internal.application.xyz
 }

Open in new window

Avatar of bmsande
bmsande

ASKER

right now I have hard coded html links that look like this...

<td class = "indent"><a HREF=/app/app.exe/open/6960183><font size = "2" color="#333333"> Project Development</font></a></td>

this works fine as the base url is unnecessary... now I have introduced an alternate sub directory /sso instead of /app, so my sso users are being directed to the /app.  

so I need to make the sub directory a variable, pulled from the browser url.  I only have client side options, don't have access to nor do I want to change the core application code.
ASKER CERTIFIED SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bmsande

ASKER

Thanks, I had to add the jquery library and then your code worked
Still trying to understand why you need to do this in JavaScript and not when you render the page?