Alert is not working in pop up window in chrome extension

前端 未结 2 948
灰色年华
灰色年华 2021-01-23 08:50

Could any one help me,to find out my problem.I have set my website as chrome extension.When I install the extension,it navigates to a popup window asking user name and password

相关标签:
2条回答
  • 2021-01-23 09:30

    The reason it is not working is that test.html is opened as a "view" of your extension and the Content Security Policy (CSP) prevents inline scripts and inline event-binding from being executed.

    You should move the code and the event-bindings to an external JS file.

    In test.html:

    <html>
        <head>
            <script type="text/javascript" src="test.js"></script>
        </head>
        <body>
            ...
            <input type="button" id="login" value="Log In" />
            ...
        </body>
    </html>
    

    In test.js:

    window.addEventListener('DOMContentLoaded', function() {
        var login = document.querySelector('input#login');
    
        login.addEventListener('click', function() {
            // ...do stuff...
        });
    });
    
    0 讨论(0)
  • 2021-01-23 09:41

    You have to pick up value of the input field:

    var uname = document.getElementById('name').value;
    
    0 讨论(0)
提交回复
热议问题