Sidebar Programming: Microsoft took away alert(), I’m taking it Back!

Developers often find the need to popup some kind of informational message to the user. We’ve all been on web sites and received the “Invalid input, please try again” alert, or the “Delete record. Are you sure?” confirmation dialog. But the JavaScript functions to do this is a Sidebar gadget have been disabled by Microsoft. In this article, I’ll show you how to take them back.

Take for example the following html page:

    <style type="text/css">
    <script type="text/javascript">
    function goWeb() {
        var el = document.getElementById("url");
        if (el.value) {
        } else {
            alert("Please enter a URL");
    <input type="text" id="url" style="width:100px" />
    <button onclick="goWeb();">Go</button>

Something like this is very common when programming a web page. This sample application allows you to enter a web address and launched it in another browser window when you click “Go”. If you don’t enter anything, you receive an error message.

Let’s add a gadget.xml manifest and turn it into a Sidebar gadget.

<?xml version="1.0" encoding="utf-8" ?>
    <name>Alert Test</name>
    <description>Alert Test</description>
        <host name="sidebar">
            <base type="HTML" apiVersion="1.0.0" src="alert.htm" />
            <platform minPlatformVersion="0.3" />

When you run the gadget and enter a web address, it launches in web browser just as it should. But, leave it blank and click “Go” and nothing happens. What happened to our error message? Unfortunately, Sidebar framework traps the “alert” method and ignores your request. But why would they do this? It’s not perfectly clear to me, nor is it documented anywhere, but one Microsoft official did state “We don’t want gadgets popping up UI that is unprompted by the user“. I agree with this in theory, but I don’t think Sidebar should make these kinds of decisions for me. So, by adding a single line to the HTML, we get back our coveted alert and confirm methods.

<script src="alert.vbs" type="text/vbscript"></script>

Place this line just above above the closing </head> element. What’s in the magical script, you ask? Well as it turns out, the VBScript MsgBox function does not suffer the same Sidebar censorship as it’s JavaScript cousins alert() and confirm(). I used MsgBox to simulate alert and confirm. Here’s the VBScript code:

'simulate JavaScripts alert() function
sub alert(prompt)
    MsgBox prompt, 48 , "Sidebar Gadget"
end sub

'simulate JavaScripts confirm() function
function confirm(prompt)
    dim res
    res = MsgBox (prompt, 33, "Sidebar Gadget")
    if res=1 then
        confirm = true
        confirm = false
    end if
end function

Now that I’ve shown you how to use alert() and confirm() within a Sidebar gadget, all I ask is that you please don’t abuse it. Personally, I’ve only use this from within a Setting dialog, which I believe is the perfect place for an alert.