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.
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>
In java script you can use concat() to join two strings together.