Learning HTML by yourself


G - Special Buttons

14/11/2011 17:54

 

A button that automatically bookmarks my site

 

      You cannot do this with HTML. However, Internet Explorer 4+ supports the window.external.AddFavorite() method, a proprietary extension to JavaScript that opens an "Add to Favorites" dialog. The following example avoids creating a non-functional button for those with other browsers, or for those with JavaScript disabled:

 

         <script type="text/javascript"><!--

         function addf() {

             window.external.AddFavorite('http://www.htmlhelp.org/',

                                         'Web Design Group'); }

         if(document.all) {

             document.write('<input type="button" onclick="addf()"'+

                            ' value="Bookmark WDG Site">'); }

         //--></script>

 

It is worth noting that readers who know how to use bookmarks almost certainly know how to bookmark your site independently. Likewise, the few readers who don't know how to bookmark your site probably won't know how to use bookmarks that you create for them. Users who don't know how to use basic functions of their browsers will only be confused when various pages imitate those functions in different ways.  This goes into the body of your text, best in the corner.  Try it out.

 

                                                                              

A button that prints my page

 

You cannot do this with HTML. However, some browsers support the JavaScript window.print() method, which opens a "Print" dialog. The following example avoids creating a non-functional button for those with other browsers, or for those with JavaScript disabled:

 

         <script type="text/javascript"><!--

         if (window.print) {

             document.write('<input type="button" onclick="window.print()"'+

                            ' value="Print This Page">'); }

         //--></script>

 

 It is worth noting that readers who have printers almost certainly know how to use their browsers' print function. Users who don't know how to use basic functions of their browsers will only be confused when various pages imitate those functions in different ways.

—————

Back