Remove junk javascript using javascript

I have a page on ASP.net where I have several content placeholders, script tags with JavaScript functions and other elements. I hide all content holders and other html elements with JavaScript except the div I want to display. But I get other scripts running on this page. How can I delete them?

Any ideas?

Edit1

Let's look at the next page

<html>
<head>

    <script type="text/javascript">
        alert("unnecessary script")
    </script>

</head>
<body>

    <script type="text/javascript">
        alert("another one")
    </script>

    <div id="div1">
        Div 1</div>
    <div id="div2">
        Div 2</div>
    <div id="div3">
        Div 3</div>

    <script type="text/javascript">
        alert("one more")
    </script>

</body>
</html>

I load this page in an iFrame on another page, where in the OnLoad () frame I call HideUnneededHTML (), which hides everything except div2. How can I remove unnecessary Javascript before it even loads?

+3
source share
1 answer

, , - , . Javascript , . , . , , . , .

<script type="text/javascript">
    function myAmazingFunction(){
       alert("Does Something");
    }
</script>

...

<script type="text/javascript">
    myAmazingFunction = function(){};

    //Now, call it... 
    myAmazingFunction();
</script>

, , , , - .

, .

Edit: , . "-", "- " .

<script type="text/javascript">
    function myAmazingFunction() {
        alert("Does Something");
    }
    myAmazingFunction();
    var temp = myAmazingFunction;
    myAmazingFunction = function() { alert("Does Something Else"); };
    myAmazingFunction();
    myAmazingFunction = temp;
    myAmazingFunction();
</script>

3 :

Does Something
Does Something Else
Does Something
+1

Source: https://habr.com/ru/post/1757623/


All Articles