我希望我站点上的出站和iframed链接应该从当前页面的url附加url参数。jquery:如何动态地将URL参数传递到页面中的链接
因此,可以说我有一个页面mysite.com和我有一个页面,导致somesite.com上的链接(或我已的iframe somesite.com上mysite.com)
现在我想的是如果有人到达我的网站,并在其中有一些url字符串(如utm_source等),如:mysite.com/?parameter1=value1 & parameter2 = value2,我应该能够将一些或所有参数值从mysite链接追加到somesite链接该网站(或iframed它)。
所以说,我希望somesite链接必须从mysite链接的url中得到parametr2的值,并在其另一个参数的值中。所以,可以说我想somesite链接是:somesite.com/?a1=[Parameter2'sValueHereFromMySiteLink]
我需要能够从源链接的任何参数中获取任何值,并将该值附加到任何地方somesite链接。
我在网上搜索,发现这个解决方案(但不工作):
$('a.my-class').each(function() {
var href = $(this).attr('href')
if(href !== undefined) {
var url = document.URL;
int index = url.indexOf("Source=");
if(index != -1){
url = url.substr(index + 7) // 7 = length of "Source="
indexx = url.indexOf("&");
if(indexx != -1)
url = url.substr(0, indexx + 1);
// now url contains the value
href = href.replace("website", url);
$(this).attr('href', href);
}
}
});
任何帮助,将不胜感激。非常感谢。
如果我可能会建议一种不同的方法。你不能在服务器端做到这一点,使页面已经加载了这些值吗? – FirstOne
谢谢,没有意识到只是加入<?php echo $ _GET ['parameter1']; ?>会做到这一点,我的坏 – gxtj
投票,但它不会显示我的投票,直到我达到15分。 – gxtj