Javascript 添加一个额外的单词来添加我的所有URL

Javascript 添加一个额外的单词来添加我的所有URL,javascript,php,jquery,asp.net,blogger,Javascript,Php,Jquery,Asp.net,Blogger,我需要在我所有的博客链接中添加额外的单词 我正在使用blogger 比如说 Url为:然后它将自动更改为 意味着我需要在我的原始链接后添加所有链接?附加词 我提到了htaccess,但blogger没有htaccess 所以请给我推荐一个javascript代码,在我所有的url中添加一些额外的单词 在java脚本中,可以使用concat()将两个字符串连接在一起 一种简单的方法(使用jQuery)是: 只要在jQuery脚本的开头包含这个小脚本,就完成了 更新: <script>

我需要在我所有的博客链接中添加额外的单词

我正在使用blogger

比如说

Url为:然后它将自动更改为

意味着我需要在我的原始链接后添加所有链接?附加词

我提到了htaccess,但blogger没有htaccess


所以请给我推荐一个javascript代码,在我所有的url中添加一些额外的单词

在java脚本中,可以使用concat()将两个字符串连接在一起

一种简单的方法(使用jQuery)是:

只要在jQuery脚本的开头包含这个小脚本,就完成了

更新:

<script>
    $(window).load(function(){
        var word='?extraword';
        $('a').each(function(){
            var thelink=$(this).attr('href');
            $(this).attr('href',thelink+word);
        });
    });
</script>
<script>
    $(window).load(function(){
        var word='?extraword';
        $('a').each(function(){
            var thelink=$(this).attr('href');
            $(this).attr('href',thelink+word);
        });
        if(window.location.indexOf(word)<0){
            window.location=window.location+word;
        }
    });
</script>
如果动态添加链接,则必须在页面完全加载后更改其
href
属性:

$(window).load(function(){
    var word='?extraword';
    $('a').each(function(){
        var link=$(this).attr('href');
        $(this).attr('href',link+word);
    });
});
再看看你博客的代码,我建议你把这个脚本放在html代码的末尾,就在关闭
正文
标记之前

更新2:

<script>
    $(window).load(function(){
        var word='?extraword';
        $('a').each(function(){
            var thelink=$(this).attr('href');
            $(this).attr('href',thelink+word);
        });
    });
</script>
<script>
    $(window).load(function(){
        var word='?extraword';
        $('a').each(function(){
            var thelink=$(this).attr('href');
            $(this).attr('href',thelink+word);
        });
        if(window.location.indexOf(word)<0){
            window.location=window.location+word;
        }
    });
</script>

$(窗口)。加载(函数(){
变量词='?外部词';
$('a')。每个(函数(){
var thelink=$(this.attr('href');
$(this.attr('href',thelink+word);
});
});
更新3:

<script>
    $(window).load(function(){
        var word='?extraword';
        $('a').each(function(){
            var thelink=$(this).attr('href');
            $(this).attr('href',thelink+word);
        });
    });
</script>
<script>
    $(window).load(function(){
        var word='?extraword';
        $('a').each(function(){
            var thelink=$(this).attr('href');
            $(this).attr('href',thelink+word);
        });
        if(window.location.indexOf(word)<0){
            window.location=window.location+word;
        }
    });
</script>

$(窗口)。加载(函数(){
变量词='?外部词';
$('a')。每个(函数(){
var thelink=$(this.attr('href');
$(this.attr('href',thelink+word);
});

if(window.location.indexOf(word)我不擅长JavaScript。如果我使用window.location=''+'?anyword',那么它只会添加到一个URL,但我需要所有URL。这只是答案的一小部分。我认为OP需要知道如何更改当前页面中的链接HREF。如果这是个问题,请查看此论坛帖子。这应该会有所帮助。如果我使用此
window.location='http://www.something.in/“+”?anyword“
,则它将只重定向一个主页,但我需要所有博客页面。这是我的博客,我已经应用了你的脚本,但它没有生效。链接是从其他地方动态添加的吗?抱歉,我无法理解。我使用了
window.location.href=“+”?anyword”
它更改了所有url,但仍在重新加载页面。我将为您编写整个脚本,您只需在关闭
正文
标记之前将其复制并粘贴到html代码的末尾。
查看更新2惊人,工作完美,将所有链接替换为?extraword。这对我来说更有用,但是已访问的页面未重定向到?extraword。它正在href标签中添加所有链接。无论如何,感谢您的帮助。