0
htmlの本文内のhref属性にfinalNameの値を渡したいとします。どうすればいいですか?javascriptの値をHTML href属性に渡すにはどうすればいいですか?
<html>
<script type="text/javascript" language="Javascript">
var url = window.location.search;
var val = getParameter('n');
var finalName = "";
if(val == false) {
var a= prompt("Enter your name & see the magic", "");
if(a){
window.location.href = '?n='+a;
document.getElementById("demo2").innerHTML = a ;
finalName = a;
}
}
else {
document.getElementById('demo2').innerHTML = val;
}
</script>
<body>
<a class="footerbtn" href="whatsapp://send?text= send you special surprise message%0A%0ATouch this blue line %0Aenter your name %0A http://magic.pagalworld.buzz/?n="
onclick="location.href=this.href+finalName;return false;"><img width="25px" height="25px" src="wp.png"/><b style="font-size: 15px;"> Click Here to Share on Whatsapp</b> <img width="25px" height="25px" src="wp.png"/></a>
</body>
</html>
あなたはそれがページをリロードすると、現在のページストップ運転上のスクリプトwindow.location' 'に割り当てます。 – Barmar
this.href + '?data =' + finalName – Kalabalik
GETリクエストで変数を渡す 'window.location'を変更した場合は、このリクエストを処理するためのサーバ言語が必要になります。その必要はありません。 –