javascript通过url传递变量
问题描述:
嗯,问题也许不正确,但我给了一个拍摄。javascript通过url传递变量
我的脚本:
<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u);void(o)" onclick="return false">OMG, testing</a>
在现实,没有JavaScript网址看起来像:
http://localhost/url=google.com
在这里想补充一点:&格式= TXT
所以,正确的url然后将是:
http://localhost/url=google.com&format=txt
- 如何&格式添加到这表明在 顶部的JavaScript“脚本”?
答
这样的:
<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u + '&format=txt');void(o)" onclick="return false">OMG, testing</a>
你只需要在文本添加到您的网址
答
的字符串,这是你想要的东西:
<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format=txt');void(o)" onclick="return false">OMG, testing</a>
答
只需将它添加到链接使用+,除非我误解了这个问题。
<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format='+txt);void(o)" onclick="return false">OMG, testing</a>
假定txt是一个变量,否则将它全部放在引号中。
答
这将做到这一点,,你必须做的一样你为本地主机
<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format='+txt);void(o)" onclick="return false">OMG, testing</a>