如何用id更改img src?

时间:2017-07-21 09:26:41

标签: firebase firebase-authentication firebase-security firebaseui

我在我的应用中使用FirebaseUI作为auth系统,但我仍然对更改源图像感到困惑。如果对于一个用户,也许这很容易,因为我可以用url图像替换manualy,但是如果我将它用于超过1个用户怎么办? 因此,每次不同的用户登录时,它都会显示来自Google帐户的不同图片。

<!DOCTYPE html>
<html>
    <head>
        <script src="https://www.gstatic.com/firebasejs/4.1.3/firebase.js"></script>
        <script src="js/config.js"></script>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    </head>
    <body>
        <h1>You Done</h1>
        <h3 id="myemail"></h3>
        <br>
        <h3 id="myname"></h3>
        <h3 id="mypict"></h3>
        <img src="https://lh4.googleusercontent.com/-SyYMKRQd6jQ/AAAAAAAAAAI/AAAAAAAAAZU/-SSniVshiV8/photo.jpg" alt="Smiley face" height="42" width="42" id="myimage">
        <button type="button" id="btnout" class="btn btn-action hide">Sign out</button>
        <script>
            const btnout            = document.getElementById('btnout');
            const superemail        = document.getElementById('myemail');
            const supername         = document.getElementById('myname');
            const superpict         = document.getElementById('myimage');
            firebase.auth().onAuthStateChanged (firebaseUser =>{
                if(firebaseUser){
                    btnout.classList.remove('hide');
                    console.log(firebaseUser.displayName);
                    console.log(firebaseUser.uid);
                    superemail.innerHTML = firebaseUser.email;
                    supername.innerHTML = firebaseUser.displayName;
                    console.log(firebaseUser.photoURL);
                   
                }else{
                    console.log('not login');
                    btnout.classList.add('hide');
                }
                console.log(firebaseUser);
            });
            btnout.addEventListener('click', e => { 
                firebase.auth().signOut();
                window.location = "/";
                window.location.href = "/";
            });
        </script>
    </body>

</html>

0 个答案:

没有答案