Edit: if there is another way of disabling javascript with javascript - I'm all ears.
I'm trying to disable javascript using javascript, by "injecting" a
<meta http-equiv="Content-Security-Policy" content="script-src 'none' ">
Into the element. The element IS added, according to Firefox dev tools -> inspector, but is ignored. Why, and how can I make a browser to "notice" it?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!--
yes, this works, but I want to do this dynamically
<meta http-equiv="Content-Security-Policy" content="script-src 'none' ">
-->
</head>
<body>
Just some javascript for tests, I hoped this will stop working,
when I'll call the disableJavaScript() function below. But it
doesn't stop
<script>
var x = 0;
setInterval(function(){
console.log(x++);
}
,1000);
</script>
Inserting the meta element:
<script>
function disableJavaScript(){
var newMetaNode = document.createElement("meta");
newMetaNode.setAttribute('http-equiv','Content-Security-Policy');
newMetaNode.setAttribute('content',"script-src 'none'");
var headElem = document.getElementsByTagName('head')[0];
headElem.appendChild(newMetaNode);
}
//calling the function after 3 seconds:
setTimeout(function(){
disableJavaScript();
},3000)
</script>
</body>
</html>