Bookmarklet: analysis of significant points, part three, reserve

  • Tutorial
In continuation of the two previous publications about the first initiating and second loading parts of the bookmarklet, for the sake of completeness, we will consider the third reserve part of the bookmarklet.

Recall briefly the logic of the “fancy” bookmarklet:
  1. By clicking on the link stored in the browser’s bookmarks, a small (up to 2000 characters) javscript code is called up, the main task of which is to organize the loading of javascript code that performs the main work of the bookmarklet
  2. The bulk of the bookmarklet after loading will do all the work.
  3. If the main part of the bookmarklet cannot be loaded, the main part of the work is performed by the backup part of the bookmarklet, as a rule, in a truncated form.


For clarity, we will illustrate the material in question, referring to the bookmarklet of the TheOnlyPage web service . Detailed information on how to install this bookmarklet can be found in the web service help system .

Most of the useful information about the backup part of the bookmarklet was given in the publication about the first initiating part of the bookmarklet , where it was indicated that:

1) The backup part of the bookmarklet is launched in case of an error loading the loaded part of the bookmarklet using the design

script.addEventListener(‘error’, function(){
// анонимная функция – обработчик ошибки 
// запускается в случае возникновения проблем...
// ...загрузки javscript-кода: script
});


2) Function - the error handler performs 2 actions:
  • Defines parameters for transferring to the backup part of the bookmarklet.
  • Calls up the back of the bookmarklet.


For the user, the graphical interface of the loaded and backup bookmarklet options can be made very similar.

The form for creating a bookmark, note or html fragment in the loaded version of TheOnlyPage bookmarklet is as follows:

image

A similar form for creating a bookmark, note or html fragment in the backup version of TheOnlyPage bookmarklet :

image

As you can see almost the same thing. There are three differences in working with the graphical interface of the downloadable and backup parts of the bookmarklet :

The first difference is that the graphical interface of the loaded part of the bookmarklet “pops up” over the current document. While the graphical interface of the backup part of the bookmarklet is displayed on a separate page, which is loaded:
  1. or instead of the current document being processed;
  2. either in a hotel browser popup window;

in any case, displaying the backup option is less obvious, since the user leaves the current page being processed.

The second difference is that the downloadable part of the bookmarklet, since it receives data when embedded in the current page, can process a large amount of data about the current web page. The backup version of the bookmarklet processes only the data that it receives in the address bar * . What data can be transmitted and its quantity is limited by the maximum size of 2000 characters of the initiating part of the bookmarklet.

For example, the downloadable part of TheOnlyPage bookmarkletcalculates the most “noticeable” visual element on the screen, which is impossible to accommodate in 2000 characters and, accordingly, this feature is not available in the backup part of the bookmarklet.

The third difference is that the downloadable part of the bookmarklet can receive data throughout the work with the current document, and the backup version of the bookmarklet receives all the data at the beginning of work, through the address bar parameters *

The main points regarding the backup part of the bookmarklet were considered in the publication about the first initiating part bookmarklet .

Here we can note another important point regarding the completion of work withbackup part of the bookmarklet. Such completion should return the user to the current web page whose data was being processed.

So, when working with the bookmarklet of TheOnlyPage web service , if you call the backup version of the bookmarklet and then click the Create button to create a bookmark, note or html fragment or Cancel to end the bookmarklet without saving the results, the bookmarklet is completed.

At the same time, instead of the page of the backup version of the bookmarklet, the current page that we worked with is loaded into the current browser window , which can be implemented with the following javascript code:

// url - адрес текущей обрабатываемой веб-страницы
window.location.replace(url);

Of course, in order for the back part of the bookmarklet to return to the current web page, the address of this page should be among other parameters transferred to the back part of the bookmarklet.



* for details on transferring parameters from the current document to the backup part of the bookmarklet, read the publication about the first initiating part of the bookmarklet

Also popular now: