Possible Duplicate:
Are there constants in Javascript?
Is there a way to declare a static of final value in javascript so that it cannot be altered by a 3rd party?
What I have is a article sharing application, with free users being ad supported. What I wish to do is prevent the free users from altering the innerHTML content by altering the storage variable for the content.
What I have at this moment is a timer that reloads the innerHTML of the article on user website every 5 seconds and I'm storing the value for the reload in a variable.
However, if a genius using jsbeatify explores which variable holds the key to removing the ad and alters that, we lose revenue and exposure of our products.
How to prevent the altering of the internal variable?
UPDATE
This is the end result of what I came up with:
<div id="specialdiv"></div>
<input type="button" value="try to change the function i to do something different" onclick="t.i = function(){alert(data.secret);}"><BR>
<input type="button" value="set function to null out of spite" onclick="t=null;">
<script type="text/javascript">
e = function(){var data = { };
Object.defineProperty(data, 'secret', {
value: "Hello world!",
writable : false,
enumerable : true,
configurable : false
});this.z=function(){window.setTimeout("try{document.getElementById('specialdiv').innerHTML = '"+data.secret+"';t.i.z();}catch(err) {document.body.innerHTML=err;}",5000);}}
g = function(){};
g.prototype = new e();e=null;window.t = {}
Object.defineProperty(window.t, 'i', {
value: new g(),
writable : false,
enumerable : false,
configurable : false });g = null;
window.t = Object.freeze(window.t); t = Object.seal(window.t);
t.i.z();
</script>
This will be presented in packed format, just to make it harder just to copy the code out of the source. This way the effort to simply copy and paste the code out will be maximized and will be very hard to automate.
Thank you all for your answers.