admin管理员组文章数量:1331849
there are few anchor tags (links on my page). I want to keep a count of how many times each link is visited and display only the ones which are mostly visited.
Is there a way to do that .?
Or
to count how many times a URL is visited is also fine.
there are few anchor tags (links on my page). I want to keep a count of how many times each link is visited and display only the ones which are mostly visited.
Is there a way to do that .?
Or
to count how many times a URL is visited is also fine.
Share Improve this question edited May 14, 2018 at 7:08 Praveen Kumar Purushothaman 167k27 gold badges213 silver badges260 bronze badges asked Jan 24, 2013 at 6:29 Nandan ChaturvediNandan Chaturvedi 1,0983 gold badges17 silver badges32 bronze badges 2- You need to store the count on the server or to an external service. No way to do it with JavaScript+HTML only. – JJJ Commented Jan 24, 2013 at 6:32
- 1 What server do you have? Can you use any programming language? – Praveen Kumar Purushothaman Commented Jan 24, 2013 at 6:33
4 Answers
Reset to default 3Using on your own server
You need a server application, which uses programming language like PHP to store and modify counts. If you have a PHP Server, there's a simple hit counter you can do with this:
<?php
$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];
?>
Using a Remote Service
If you don't have the option of hosting a script on your server, you can use some hosted solutions like:
- Hit Counter HTML Code Well, the name says it all, you can give the counter an Initial start count of your counter !!.
- ewebsitecounter has the fanciest icons among all tumblr hit counters available for free. You can choose from many different layouts, including animals and seasonal pics.
- Hit-Counter, definitely the most popular tumblr online counter outthere. Please be careful when entering the details for your blog since the site it’s full of ads.
- Online Users Counter
- Supercounters - free hit counter,users online counter flag counter visitor map for website blog and tumblr
- HitWebCounter - The most widely used Free internet Counter.
You can use google analytic tools for such information you can find more over here Alternatively you can put your logic in server side to count the hits each url in your website is getting.
You can user cookies, similar to this one.
$(document).ready(function() {
if (!$.cookie("urlCookie")) {
var url = document.referrer;
var match = url.indexOf("localhost");
if (match != -1) {
$.cookie("urlCookie", url);
$("#title").html(url);
}
} else {
$("#title").html($.cookie("urlCookie"));
}
});
<h1 id="title"></h1>
Personally I would use server side code or analytics to acheive this, but since you've tagged as a HTML5/JavaScript question, you could do something along the lines of:
if ( localStorage ) {
jQuery( 'a' ).click( function () {
var urls = localStorage.getItem( 'urls' );
urls = ( urls != null ) ? JSON.parse( urls ) : {};
urls[ this.href ] = urls[ this.href ] || 0;
urls[ this.href ]++;
urls = JSON.stringify( urls );
localStorage.setItem( 'urls', urls );
});
}
More information here http://www.html5rocks./en/features/storage
本文标签: javascriptcount number of times a url is visitedStack Overflow
版权声明:本文标题:javascript - count number of times a url is visited - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742272991a2444658.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论