Take for example the following html page:
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" ?> <gadget> <name>Alert Test</name> <namespace>MyNamespace</namespace> <version>184.108.40.206</version> <copyright></copyright> <description>Alert Test</description> <hosts> <host name="sidebar"> <base type="HTML" apiVersion="1.0.0" src="alert.htm" /> <permissions>full</permissions> <platform minPlatformVersion="0.3" /> </host> </hosts> </gadget>
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>
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.