开发者

Hiding/Obfuscating A Javascript Variable In The Source

Let's say, for the sake of argument, I have a page with a progress bar that's advancing based on the number of times a certain hashtag has been tweeted on Twitter. This could be generated something like this:

tweets = <?php echo $tweetsfile->total; ?>;
target = <?php echo $target; ?>;
$('#progressbar').css('width', tweets / (target/100) + '%');

Supposing that it's undesirable for people to be able to look at the source code and see what the target number is. Is there a simp开发者_如何学Pythonle strategy for keeping this information from prying eyes?


instead of doing the calculation client side, do it server side.

$('#progressbar').css('width', <?php echo ($tweetsfile->total / ($target/100)); ?> + '%');


You can simply compute the percentage serverside (php) and not clientside.

$progress = ($tweets / ($target/100));

And output only $progress, which will be the percentage.

$('#progressbar').css('width', $progress + '%');


Try just calculating the percentage in php:

progressPercent = <?php echo (100 * $tweetsfile->total / $target); ?>;
$('#progressbar').css('width', progressPercent + '%');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜