admin管理员组文章数量:1323335
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 pleting its mission?
thanks
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 pleting its mission?
thanks
Share Improve this question asked Jun 17, 2013 at 6:06 gerrnargerrnar 4171 gold badge7 silver badges15 bronze badges 22- I am not sure, you can remove code, while it is being executed. – LuigiEdlCarno Commented Jun 17, 2013 at 6:08
- Why you want to remove it? You can unbind the event/function when you don't need it.. – Paritosh Commented Jun 17, 2013 at 6:08
- 3 You could theoretically remove it from the DOM but it will still be in the page source. Javascript is executed on the client side so by definition the user already has a copy of it. – Mark Parnell Commented Jun 17, 2013 at 6:13
- 2 Even if you remove HTML from CTRL+U page, user will just press F12 and copy table from Firebug/Developer Tools. – dfsq Commented Jun 17, 2013 at 6:21
- 1 Then learn Ajax, removing JS-code much more difficult then AJAX... – Karl Adler Commented Jun 17, 2013 at 6:30
4 Answers
Reset to default 4I 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>
Demo
Update:
As Juhana points out in the ments, 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.
You can remove script element or do anything else but user can still get the table through debug mode. There are some ways to encrypt your source code,try: http://jsobfuscate./
document.currentScript.remove()
May be you can make it hard by disabling copy and paste function in your webpage:
<script type="text/JavaScript">
function killCopy(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=killCopy
document.onclick=reEnable
}
</script>
see http://www.boogiejack./no_copy_paste.html
But still users can get it, because they already have a copy of html on their local machine
本文标签: htmljavascript code remove itself after being runStack Overflow
版权声明:本文标题:html - javascript code remove itself after being run - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742136237a2422383.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论