简体   繁体   中英

how do i fix this Uncaught ReferenceError?

I am pretty new to java script. I am following along on a tutorial on how to get firebase to authorize on my page. I just have a simple button that SHOULD pull up the google login.

The error is "(index):96 Uncaught ReferenceError: googlelogin is not defined at HTMLButtonElement.onclick ((index):96) onclick @ (index):96"

Im pretty certain this is an easy fix. Like I said, fairly new. Thanks in advance!

In the HTML

<body>
    <h1>testing</h1>
    <button onclick="googlelogin()">login</button> 

    <script>
        src = "app.js"
    </script>
</body>

In app.js

document.addEventListener("DOMcontentloaded", event => {

        const app = firebase.app();
        console.log(app)

    )
}

function googlelogin() {
    const provider = new firebase.auth.GoogleAuthProvider();

    firebase.auth().signupwithpopup(provider)

    .then(result => {
            const user = result.user
            document.write('Hello $(user.displayname');
            console.log(user)
        })
        .catch(console.log)

Your current code just sets a global variable called src to the value of app.js . I think you want to actually load app.js

<body>
    <h1>testing</h1>
    <button onclick="googlelogin()">login</button> 

    <script src="app.js"></script>
</body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM