首先感谢Dev Chen& sideroxylon用于解答我之前的问题。我几乎接近解决方案,但它没有成功......?
在以下代码中,我们获得了值1&来自User&的Value2当他按下GO按钮时,它会进入
http:// foo.com/document/ value1 / value2 /pageview.html
此代码没问题!它给出了警报,但是当我将其更改为goto URL时,它不能在我手中工作,请看看它?
HTML
A: <input type="text" id="value1"/><br />
B: <input type="text" id="value2" /> <br />
<input type="button" value="GO!" onclick="redirect()" />
的Javascript
function redirect() {
alert("Set window.location to:http://www.foo.com/document" + document.getElementById("value1").value + "/" + document.getElementById("value2").value + "/printview.html");
}
(这是旧问题http://goo.gl/x85m6H)
它的给予和提醒......如何更改它以便它转到URL。
它的警报功能如何让它转到计算出的链接?
答案 0 :(得分:1)
像这样:
window.location.href = newUrl;
您的redirect
功能可以更改为:
function redirect() {
window.location.href = 'http://www.foo.com/document/'
+ encodeURIComponent(document.getElementById("value1").value)
+ '/'
+ encodeURIComponent(document.getElementById("value2").value)
+ "/printview.html";
}