Ho inserito un URL assoluto nel mio JavaScript che ho hard coded per window.location.
Non voglio doverlo modificare ogni volta che sto testando la mia app. In PHP avrei gestito questo testando la variabile $ _SERVER ["HTTP_HOST"] per scoprire quale server sono attivo e regolare di conseguenza. Tuttavia, non ho familiarità con Java e mi chiedo se ha un metodo simile? O se forse anche JavaScript avesse un metodo simile?
Il codice è il seguente:
var url = "http://172.17.1.107/store/results/index.jsp";
window.location = url;
Quello che vorrei fare è:
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 avrei solo fatto questo:
var server = <?= $_SERVER["HTTP_HOST"] ?>
var url = "http://" + server + "/store/results/index.php";
window.location = url;
Tutte le idee ? Suppongo che io stia operando partendo dal presupposto che devi fare un URL assoluto per cambiare la posizione della finestra corrente in JavaScript. Se esiste un altro modo per modificare la posizione della finestra in JavaScript senza un URL assoluto, non esitare a offrirlo.
Grazie in anticipo ...
Sì, certo, e l'acqua è blu. HTF è correlato !!! –