Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

javascript - 如何将包含多个参数的URL传递到URL?(How do I pass a URL with multiple parameters into a URL?)

Basically I'm trying to pass a URL like this:(基本上我正在尝试传递这样的URL:)

www.foobar.com/?first=1&second=12&third=5

into a URL like this:(进入这样的URL:)

http://www.facebook.com/sharer.php?&t=FOOBAR&u=http://www.foobar.com/first=12&sec=25&position=2

It only recognizes the first parameter.(它只识别第一个参数。)

I'm having the same problem with LinkedIn and Twitter sharing, so it must be something I'm doing wrong.(我在LinkedIn和Twitter分享方面遇到了同样的问题,所以一定是我做错了。)   ask by DormoTheNord translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Rather than html encoding your URL parameter, you need to URL encode it:(您需要对URL encode ,而不是html encoding您的URL参数进行html encoding :)

http://www.facebook.com/sharer.php?&t=FOOBAR&u=http%3A%2F%2Fwww.foobar.com%2F%3Ffirst%3D12%26sec%3D25%26position%3D

You can do this easily in most languages - in javascript :(您可以在大多数语言轻松完成此操作 - 在javascript中 :)

var encodedParam = encodeURIComponent('www.foobar.com/?first=1&second=12&third=5');
// encodedParam = 'http%3A%2F%2Fwww.foobar.com%2F%3Ffirst%3D12%26sec%3D25%26position%3D'

(there are equivalent methods in other languages too)((也有其他语言的等效方法))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...