Alert is not working in pop up window in chrome extension

前端 未结 2 979
灰色年华
灰色年华 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:

    
        
            
        
        
            ...
            
            ...
        
    
    

    In test.js:

    window.addEventListener('DOMContentLoaded', function() {
        var login = document.querySelector('input#login');
    
        login.addEventListener('click', function() {
            // ...do stuff...
        });
    });
    

提交回复
热议问题