I use an absolute URL in my JavaScript, which I hardcoded for window.location.
I do not want to change this every time I test my application. In PHP, I would handle this by testing the $ _SERVER ["HTTP_HOST"] variable to find out which server I’m on and adjust accordingly. However, I'm not so familiar with Java, and I wonder if it has a similar method? Or maybe even JavaScript had a similar method?
The code is as follows:
var url = "http://172.17.1.107/store/results/index.jsp";
window.location = url;
What I would like to do:
var server = [something that returns just 172.17.1.107 (with or without the http:// is fine)]
var url = "http://" + server + "/store/results/index.jsp";
window.location = url;
In PHP, I would just do this:
var server = <?= $_SERVER["HTTP_HOST"] ?>
var url = "http://" + server + "/store/results/index.php";
window.location = url;
? , , URL-, JavaScript. JavaScript URL-, , .
...