Issue
I am looking for a way to fill an array table by javascript code then remove that code not to allow users copy the table directly(or at least make it hard) from page as HTML.
<script>
....
</script>
how to remove the java script from the page after completing its mission?
thanks
Solution
I don't really see a point in removing the JavaScript, but it would be possible. Give the script-element an ID to make it easier to select. Then place the code that will handle the removal in a separate script-element.
Given that the code you wan't to remove isn't asynchronous, something like this would do it:
<script id="foo">
// Do your stuff here, create the table or whatever necessary
</script>
<script>
(function () {
var node = document.getElementById("foo");
if (node.parentNode) {
node.parentNode.removeChild(node);
}
})();
</script>
Update:
As Juhana points out in the comments, this will remove the script-element from the DOM, but the script element will still be visible if you look at the actual source of the page.
Answered By - Christofer Eliasson
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.