2014-11-08 73 views
0

我不得不处理在多个网址,应在URL查询参数传递的情况下,例如:通过URL查询中多个URL PARAMS

http://example.com/?landing=<url1>&referrer=<url2> 

url1: http://test1.com/test.html?param=x&param2=y 
url2: http://test2.com/test/test.html?p=x&c=&... 

目前我正在努力没有成功如下:

var l = encodeURIComponent(document.URL); 
var r = encodeURIComponent(document.referrer); 
window.location.href = 'http://example.net/?landing=' + l + '&ref=' + r; 

我的问题是:什么 将编码URL1和URL2的最佳方式?我应该使用encodeURIComponent还是使用base64编码来处理那些参数或者其他的东西?

回答

0

对网址编码的整个参数没有问题,但是如果您编码的是完整网址,则应使用encodeURI而不是encodeURIComponent

这里可能存在的一个问题是,作为查询字符串参数传递的第一个和/或第二个URL可能会达到maximum characters allowed in an URL,但只要您可以预测这种情况永远不会发生,那么您仍然可以再次正常工作!

关于base64方法,您可以轻松地达到URL限制中允许的所谓最大字符数。