0

I have HTML pages with relative paths, for example this example below will use the base and relative path if base = www.test.com/img/testHtmlPage.html

<a href="/img/testHtmlPage.html">

I want to know is there any way in html to take as variable the root or the base(in my case test.com as variable) and use it in another link like this

<a href="www.anotherLink.test.com/img/testHtmlPage.html">

In my case I have another link but it use same root.
P.S. I'm sorry if the question is made up incorrectly, I try my best.

  • I am not sure if I understand question correctly but this should be your solution: https://stackoverflow.com/questions/15439853/get-local-href-value-from-anchor-a-tag – Oliver Kurnava Aug 04 '21 at 09:19
  • It may be my solution dear Oliver Kurnava, but in my case I can't use any script tag in the html page – Eric Harutyunyan Aug 04 '21 at 09:36

1 Answers1

0

If you have a php file which is link to your html you can pass the host variable to it.

So you can do something like that :

1 - Retrieve your host path in variable by using this in PHP : $host = $_SERVER['HTTP_HOST'];

2 - Put php $host in your html path : <a href="<?php echo $host ?>/img/testHtmlPage.html">

Dharman
  • 30,962
  • 25
  • 85
  • 135
Julien
  • 1