Page 136 - DCAP312_WEB_TECHNOLOGIES_II
P. 136

Web Technologies-II



                   Notes         is by far the most common platform for ASP.NET websites. While there are some open-source
                                 options available for Linux-based systems, these alternatives often provide less than full support
                                 for ASP.NET applications.

                                 7.1 Communicating with the Browser

                                 There are numerous scenarios where it is helpful to integrate a desktop function with the web
                                 browser.  Given  that  most  users  spend  the  widely  held  of  their  time  today  surfing  the  web
                                 in their browser of choice, it can make sense to provide some sort of incorporation with our
                                 desktop application. Often, this will be as simple as long as a way to export the current URL or
                                 a selected block of text to our application. For this, we have created a very simple application
                                 that uses text to speech to speak out loud the currently selected block of text in our web browser.
                                 Internet Explorer provides many hooks for integrating application logic into the browser, the
                                 most popular being support for adding custom toolbars. Chrome plug-in architecture which
                                 uses XML for the UI layout and JavaScript for the application logic.
                                 What about the other browsers, Google Chrome, Safari, and Opera? Given there is no common
                                 plug-in architecture used by all browsers, we can see a huge development effort is required to
                                 provide a separate toolbar implementation for each browser.
                                 It would be nice to be able to write one toolbar that could be used across all browsers. This is
                                 not possible today, but we can achieve almost the same effect using Bookmarklet.

                                 7.1.1 Bookmarklet
                                 A bookmarklet is special URL that will run a JavaScript application when clicked. The JavaScript
                                 will execute in the context of the current page. Like any other URL, it can be bookmarked and
                                 added to our Favourites menu or placed on a Favourites toolbar. Here is a simple example of
                                 a bookmarklet:
                                           javascript:alert(‘Hello World.’);
                                           Here is a slightly more complex example that will display the currently
                                           selected text in a message box:
                                           <a href= “javascript:var q = ‘’; if (window.getSelection)
                                           q = window.getSelection().toString(); else if (document.getSelection)
                                           q = document.getSelection(); else if (document.selection)
                                           q = document.selection.createRange().text; if(q.length > 0)
                                           alert(q);  else  alert(‘we  must  select  some  text  first’);”>Show  Selected
                                           Text</a>
                                 Now, drag the bookmarklet and drop it on our Favourites toolbar (for IE, we need to right click,
                                 select Add to Favourites, and then create it in the Favourites Bar). Navigate to a new page, select
                                 a block of text, and click the Show Selected Text button. Once again, the selected text will be
                                 shown in a message box. We can see the potential of bookmarklets. We can create a bookmarklet
                                 for each command of our application and display them on a web page. The user can then select
                                 the commands they want to use and add them to their Favourites (either the toolbar or menu).
                                 The downside is it is slightly more effort to install than a single toolbar, but on the upside, it
                                 gives the user a lot of flexibility. They need only choose the commands they are interested in
                                 and can choose whether they want them accessible from a toolbar or menu. From a developer’s
                                 perspective, bookmarklets are great as they are supported by all the major browsers. The only
                                 thing we need to worry about is making sure our JavaScript code handles differences in browser
                                 implementations, something that is well documented and understood these days.




        130                               LOVELY PROFESSIONAL UNIVERSITY
   131   132   133   134   135   136   137   138   139   140   141