doudeng2184 2015-06-26 17:03
浏览 83
已采纳

添加一个额外的单词来添加我的所有网址

I need to add extra word in all my blog link.

I am using blogger.

For example.

The Url is : http://wwww.example.com/post1.html then it will automatic change to http://wwww.example.com/post1.html?extraword

means i need to add in all link ?extraword after my original link.

I have referred .htaccess add an extra word to add all my URLs but it about htaccess, but blogger doesn't have htaccess.

so please suggest me a code with javascript, with add some extra word in all my url.

  • 写回答

2条回答 默认 最新

  • doutiaoku4495 2015-06-26 17:24
    关注

    one simple way (using jQuery) is this:

    var word='?extraword';
    $('a').each(function(){
        var link=$(this).attr('href');
        $(this).attr('href',link+word);
    });
    

    just include this little script at the beginning of your jQuery script and it's done.

    UPDATE:

    if the links are added dynamically you must change their href attribute after the page is completely loaded:

    $(window).load(function(){
        var word='?extraword';
        $('a').each(function(){
            var link=$(this).attr('href');
            $(this).attr('href',link+word);
        });
    });
    

    also looking at your blog's code I suggest that you put this script at the end of your html code right before the closing body tag.

    UPDATE2:

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

    UPDATE3:

    <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动