英文:
JavaScript redirect using URL parameters that contains "@"
问题
我试图使用JS函数在按钮点击时重定向到一个新页面。
URL应包含电子邮件地址参数。
<form>
<input type="email" id="mail" placeholder="YOUR EMAIL ADDRESS" required/>
<input type="submit" value="SEND US THE LIST" onclick="redirect();"/>
</form>
<script>
function redirect(){
var email = document.getElementById("mail").value;
window.location.replace("https://rinateithan.com/thank-you?sender="+email);
}
</script>
我已经测试了我的代码,一旦我在URL参数中使用普通字符串,包含 "@" 和 "." 符号,代码就能正常工作。
但一旦我在URL参数中使用电子邮件地址,重定向就失败了。
console.log("https://rinateithan.com/thank-you?sender="+email); // 例如,返回 https://rinateithan.com/thank-you?sender=test@gmail.com
如何使用JavaScript重定向通过URL参数传递电子邮件地址?
英文:
I'm trying to redirect to a new page on button click using JS function.
The URL should contain email address parameter.
<form>
<input type="email" id="mail" placeholder="YOUR EMAIL ADDRESS" required/>
<input type="submit" value="SEND US THE LIST" onclick="redirect();"/>
<script>
function redirect(){
var email = document.getElementById("mail").value;
window.location.replace("https://rinateithan.com/thank-you?sender="+email);
}
</script>
I have tested my code, once I use normal string with "@" and "." symbols the code works fine.
But once I use email address in the URL parameters the redirect fails.
Console.log("https://rinateithan.com/thank-you?sender="+email); // Returns https://rinateithan.com/thank-you?sender=test@gmail.com for example
How can I transfer email address through URL parameters using JavaScript redirection?
答案1
得分: 1
@
在 URL 中是不允许的
const email = 'test@gmail.com'
console.log("https://rinateithan.com/thank-you?sender="+encodeURIComponent(email));
英文:
@
is not allowed in the url
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const email = 'test@gmail.com'
console.log("https://rinateithan.com/thank-you?sender="+encodeURIComponent(email));
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论