Please guys i need help with this code JS

<!DOCTYPE html>
<html>
<body>
<style>
.font {
    font-family: "Times New Roman", Times, serif;
    width: 3px;
    font-size: 20px;
    font-weight:600;
    height: 8px;
    margin: 02px;
    padding-left: 0px;
    padding-right: 0px;
    padding: -14px;

}

</style>

<p class="font" style="color:black" id="counter"></p>
 
<script>
var n = localStorage.getItem('on_load_counter');
 
if (n === null) {
    n = 0;
}
 
n++;
 
localStorage.setItem("on_load_counter", n);
 
document.getElementById('counter').innerHTML = n;
</script>

</body>
</html>

Just guys look at it in View numbers i want to make it like this :
1000 - 1k
10000 - 10k
1000000- 1m

Please guys improve it for me and others who really appreciate that for you guys


Share your read only link please. It will help people diagnose your problem faster;

2 Likes

I feeling crazy …!!!

http://ondrous-project.webflow.io/

Hey @JaryLuad

That is not a share link. See the link above on how to make one.

Here is :slight_smile:

https://preview.webflow.com/preview/ondrous-project?preview=3d4ad21c00ae51f2ef0af70aef6087c9

Do you have experience sir about JS ???

I have some modest experience with JS although for this case, there is no solid way to do this without a access to some sort of database using a language like PHP;

Your method uses LocalSessionStorage which is dependent on someone not clearing the cache and will always default to 1 for a first time visitor. Additionally, it only looks at the current page (blog) views and not the actual number of visits to the article page itself. Your method will however work well on the individual article page

Basically what I am saying is that this functionality cannot be implemented on the main blog/articles page since there is no way (not natively at least) to fetch the number of visits to a particular article and the display it on the main page.

What do you think of this @samliew ?

1 Like

I agree with you but i use this method of JS as in the front page and i cannot embed the View.php in my site data so, even if i make changes on the code it will be the same in the single post >>>

Maybe you this trick But you can try with this code embed in single post !!!

@thesergie @PixelGeek @samliew ???

Both links are NOT working

1 Like

This topic was automatically closed 125 days after the last reply. New replies are no longer allowed.