![](/img/trans.png)
[英]Need to open a new window with Javascript and pass query strings stored in a string variable in C#
[英]Need to pass in url variable with Javascript to open new browser window
我正在嘗試通過傳遞“演示”段中的可變網址來打開一個窗口。 我可能正在做一些很明顯的錯誤,但是對javascript來說是很新的。 任何幫助,不勝感激,因為這是行不通的!
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Click me</button>
<p id="demo">www.google.com</p>
<script>
function myFunction() {
var name = document.getElementById("demo").innerHTML;
var name2 = encodeURIComponent(name);
window.open(name2, "_blank");
}
</script>
</body>
</html>
只需添加“ http://”字符串
window.open("http://"+name2, "_blank");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.