I'm having a problem with HTML in Google Sites

Issue

Because I don’t understand Google Scripts, I use Google Sites, and when ever I try put this code in, nothing happens, so I used another piece of code that would tell me if it wasn’t working, and it said "User canceled request", when you click the button, a drop down of updates, and upcoming updates should appear, but nothing happens.

<button onclick="myFunction()">Press for Announcements</button>
<script>
function myFunction(){
  alert("New:\n- New Code\n- Update Button\n- About the Creator Section\n- Contact the Creator\n\nComing Soon:\n- Quote Code YouTube Channel\n- More Codes\n- Accounts\n- Commenting\n- Pre-made Code\n- C/C++\n- Code Sandbox");
}
</script>

Solution

Your issue is that you are unable to use alert dialogs in Google Sites. Google Scripts can be confusing. It’s usually good to open up the web console as these errors should give you some idea of what is going on.

This change will add your text into a new DIV within the site. I imagine you want it to do much more, but hopefully this helps you understand what was going wrong.

<button onclick="createHTMLalert()">Press for Announcements</button>
<script>

    function createHTMLalert(){
        if(!document.getElementById('announcements_alert')){
            let announcements_alert = document.createElement('div');
            announcements_alert.id = 'announcements_alert';
            document.body.appendChild(announcements_alert);
            announcements_alert.innerText = "New:\n- New Code\n- Update Button\n- About the Creator Section\n- Contact the Creator\n\nComing Soon:\n- Quote Code YouTube Channel\n- More Codes\n- Accounts\n- Commenting\n- Pre-made Code\n- C++ and C for Game Making\n- Quote Code Twitter Page\n- Code Park";
        }
    }
</script>

Answered By – Andre Bradshaw

Answer Checked By – Timothy Miller (AngularFixing Admin)

Leave a Reply

Your email address will not be published.