KayakinKoder
KayakinKoder

Reputation: 3451

HTML form with no action (+ CSP rule no inline javascript)

In the past when I've wanted to disable the default action of a form, I've done

<form action="javascript:void(0);">

We now employ a CSP (Content Security Policy) to disallow inline JavaScript. How can we disable the default form action without the inline js?

Upvotes: 3

Views: 861

Answers (2)

Null
Null

Reputation: 1086

You can disallow all form actions from the HTML document by setting form-action 'none'.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/form-action

Upvotes: 1

Amospikins
Amospikins

Reputation: 126

use jquery

<script>
    $(document).ready(function () {

        $("#form").submit(function (e) {

            //stop submitting the form 
            e.preventDefault();
            return true;

        });
    });
</script>

Upvotes: 1

Related Questions