1

i have a fake visitor's counter script which code in javascript but i want to use it in smarty tpl file i am try to do it but its not displaying where i want. the script code is below

<!--Simply copy and paste it where you wish the counter to appear.-->


<SCRIPT language="JavaScript" type="text/javascript">
// counter - from http://rainbow.arch.scriptmania.com/scripts
function fakecounter(){

//decrease/increase counter value (depending on perceived popularity of your site!)
var decrease_increase=2460

var counterdate=new Date()
var currenthits=counterdate.getTime().toString()
currenthits=parseInt(currenthits.substring(2,currenthits.length-4))+decrease_increase

document.write("You are visitor # <b>"+currenthits+"</b> to my site!")
}
fakecounter()
</script>

and i am trying to using it in after </script> .

1 Answer 1

1

This script should work without a problem. If you put it in clean Smarty template file you get information similar to:

You are visitor # 945155 to my site!

However in older versions of smarty you need to use {literal} to use JavaScript, so your code should look like this:

<!--Simply copy and paste it where you wish the counter to appear.-->


<SCRIPT language="JavaScript" type="text/javascript">
    {literal}
    // counter - from http://rainbow.arch.scriptmania.com/scripts
    function fakecounter() {

//decrease/increase counter value (depending on perceived popularity of your site!)
        var decrease_increase = 2460

        var counterdate = new Date()
        var currenthits = counterdate.getTime().toString()
        currenthits = parseInt(currenthits.substring(2, currenthits.length - 4)) + decrease_increase

        document.write("You are visitor # <b>" + currenthits + "</b> to my site!")
    }
    fakecounter()
    {/literal}
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.