使用URL更改链接(URL链接中的html标记)

时间:2013-03-08 22:08:39

标签: javascript jquery url

我正在尝试编写一个脚本,就像这样: 1.有人点击电子邮件中的链接:http://www.domain.com/page/?e=email@usersemail.com 2.当它们落在页面上时,它会检测到URL具有与之关联的电子邮件地址并删除现有的href并使用带有新链接的onclick功能。 (我尝试更换href属性,但这不起作用)

这是我的代码:

$(function(){
    var channel = 'default';
    var url = window.location.href;

    if(url.match(/e=(.*)/)) {
        channel = url.match(/e=(.*)/)[1];
        changeLinks(channel);
    }
});

function changeLinks(channel) {
    var beforeURL = 'http://www.differentdomain.com/emailcheck.aspx?FormName=1881&e=<spanclass=emailclass>';

    var afterURL = '</span>&url=https://www.domain.com/order-page#us&page=us';

    $('a.LinkClicked').removeAttr('href');
    $("a.LinkClicked").click(function() {
        window.open(beforeURL + channel + afterURL);
    });

HTML很简单:

<a class="LinkClicked" href="/order-page/">Link</a>

现在的问题是,点击后,标签不会加载到URL中。此外,这个页面是一个aspx页面,这有什么不同吗?

最终结果应该是使用链接打开一个新页面,基于用户的电子邮件地址(因此每次电子邮件都会有所不同,具体取决于用户):

http://www.differentdomain.com/emailcheck.aspx?FormName=1881&e=<spanclass=emailclass>email@usersemail.com</span>&url=https://www.domain.com/order-page#us&page=us

0 个答案:

没有答案
相关问题