Add script to favorites. Add to favorites for all browsers. Removing a folder from Favorites

In any of modern browsers There is a function to add sites to your favorites list. In this way, the user can save favorite sites and keep them always at hand in order to have access to them fast access. But for a long time The "Add to Favorites" button for the site was popular. This function somewhat simplifies the process of adding a site to bookmarks and allows you to once again remind the user that it would be a good idea to add the site to favorites.

Psychology is at work here. The fact is that when a user sees an offer to add to favorites on a website, he wonders whether he needs it. And if he decides that the site is really useful, he will add it to his list of bookmarks. And if there is no offer, the user will not even think about this issue. That is why it is necessary to offer: whoever knocks, the door is opened.

Of course, most visitors bookmark pages not because they plan to return to the site every day, but “just in case they need it,” and, as a rule, do not return. But some users return regularly and form the core of visitors. One way or another, if people return to the site, it means that your site is useful, and this will have a positive impact on behavioral factors your resource, which will allow search engines treat him with great confidence.

You need to place the “Add to Favorites” button on your website in a visible place, but not too intrusively. The best place for such a button - the header or side part of the site.

There is no need to make the button too huge or too small. Remember that the button should fit into the overall design of the site, and not be too intrusive or too inconspicuous.

Code for the "Add site to favorites" button

Most modern browsers, with the advent of the HTML5 standard, support rel attribute="sidebar" .

Adding a site to your favorites - "Nubex" function addSite() ( if (document.all) window.external.addFavorite("http://site", "Site builder "Nubex""); )

Don't forget to bookmark our site! (For browser Google Chrome press Ctrl+D)

Add site to favorites

But remember that in Google browser Chrome is unable to bookmark a site using a button on the site. For this there is special combination keys: Ctrl+D, so don't forget to tell the user about this.

You can track the number of users who have bookmarked your site, for example, using the Yandex.Metrica service (“Attendance” - “Conversions”).

Cross-browser bookmarking of a page is implemented with using JavaScript. To add a page to browsers' Favorites Internet Explorer and browsers running on the IE engine, is called standard method AddFavorite. However, there is one important detail here. If the IE page is opened as an embedded object in another application, for example in plugins or when using components for working with html, then the window.external object is present, but its AddFavorite method does not work. This is the most common mistake developers who simply copy each other's code without understanding or testing it. It would also be a big mistake to use only this one method on your website.

Gecko-based browsers such as Firefox, Netscape, K-Meleon and others have a window.sidebar object and a method for adding addPanel . The third parameter of the method is undocumented and optional, so in the script it is simply replaced empty line. Please note that by default the link is not added to bookmarks, but to sidebar browser. To add a page to the desired folder bookmarks, select it from the drop-down menu.

For the Opera browser, the bookmark link must have the attribute rel="sidebar" . But if this attribute is set immediately by default, then some browsers like Netscape will work out the bookmarking function twice: the first time through the script and the second time through the rel attribute. Therefore, you will have to change the link attributes dynamically, having previously determined the browser by checking the opera object type.

If none of the listed methods did not work, then there is no need to issue an error message or, even worse, silently terminate the script. It would be much more correct to show the user affordable option solving a problem, for example, offering to manually press the key combination Ctrl+D.

Now that we have all the initial data, we can write a cross-browser script to bookmark the page. I got something like this:

// Add to Favorites function add_favorite(a) ( title=document.title; url=document.location; try ( // Internet Explorer window.external.AddFavorite(url, title); ) catch (e) ( try ( // Mozilla window.sidebar.addPanel(title, url, "" ) catch (e) ( // Opera if (typeof(opera)=="object") ( a.rel="sidebar"; a.title=title ; a.url=url; return true; ) else ( // Unknown alert("Press Ctrl-D to bookmark this page"); ) ) return false;

Add to favorites

You can see a working example of the implementation right on this page. The use of try-catch constructs allows the script to work correctly in any non-standard situations, for example in an IE Tab window opened in Firefox browser. The script also works correctly in various exotic browsers that cannot be uniquely determined through UserAgent or DOM properties. All vaunted commercial products like DLE are silently broken down in this situation.

Good bad

    Website pages in their functionality strive for opportunities full applications, which mainly falls on the shoulders of JavaScript. One of the challenges that arises...

    When the page size exceeds a certain limit, developers often put a text or graphic link “to the top of the page” at the bottom. This link allows...

This article will talk about in different ways adding folders, files and programs to the Favorites list file manager Windows operating system - Explorer.

In the operating room Windows system, in Explorer there is a list of “Favorites”. To this list operating system by default links to specific folders(for example, “Desktop”), as well as in the folders of some programs after installing them (for example, cloud folders file storages Google Drive, SkyDrive (OneDrive), Yandex.Disk and others).

You can easily add other new folders to the Favorites list, or remove folders located there from the Favorites list.

First, let's look at adding links to folders to the Favorites list, as well as removing them from this list.

Removing a folder from Favorites

To remove a folder from the “Favorites” list, you just need to move the mouse cursor to the desired folder and click on the right mouse button. In the context menu you need to select the “Delete” item and after that the folder will be deleted from this list.

Adding a folder to Favorites

To add a new folder to Favorites, you must first open File Explorer. Then you need to select the desired folder and simply drag it, while holding down the mouse button, into the Explorer window into the “Favorites” list. In this case, the inscription “Create a link to Favorites” will be visible next to the dragged folder.

You can add a folder in another way. To do this, you need to open Explorer, and then in the Explorer window, open the folder that you want to add to the Favorites list. In this image, the CD-DVD folder is selected.

After that, it appears in “Favorites” new folder, in the example given - the “CD-DVD” folder.

Recovery deleted folders To favorites

After removing the default folder links, you can restore them. To do this you need to click right click mouse on “Favorites”, and then select “Restore favorite links” in the context menu.

Deleted links to folders that were set to Favorites by default will be restored. This action will not affect previously added folders to Favorites; links to these folders will remain in the Favorites list.

Adding programs to Favorites

Using the methods described above, you cannot add program shortcuts to Favorites. When you try to move a program shortcut to “Favorites”, the message “Could not be placed in “Favorites”” appears.

You can work around this obstacle by opening the Links folder, which contains the contents of the Favorites list.

If the program that you need to add to “Favorites” does not have a shortcut, then you need to create a shortcut for this program and send it to the Desktop.

A shortcut for a program is created in this way - “Start” menu => “All programs” => Select the program and right-click on it => in the context menu select “Create shortcut” => “You cannot create a shortcut in this folder. Should I put it on my desktop?” => “Yes.” Now the shortcut for the selected program is placed in the Desktop folder.

After the folder with the program shortcut has been opened in Explorer or the shortcut for the selected program is on the Desktop, you need to open the “Start” menu and in the very right top corner open your personal folder (the name of your user folder). The contents of the Favorites list are located in the Links folder.

Open File Explorer, and then drag a program shortcut to the Links folder from the folder that contains the shortcut for the selected program. If the shortcut for the selected program is on the Desktop, then simply drag the shortcut to the “Links” folder with the mouse.

In the image I dragged the label Skype programs to the "Links" folder, and immediately after that the "Skype" shortcut appeared in the "Favorites" list. In the Favorites list, program shortcuts are displayed without an arrow.

Adding files to Favorites

This is exactly how you can add to your Favorites list. separate files. First you need to select a file that will be placed in the “Favorites” list.

For example, I chose " Word document" with the name "Questions". You will need to right-click on the selected file and select “Create shortcut” in the context menu.

Before moving a file shortcut, you can remove the ending “Shortcut” from the file shortcut so that the shortcut name does not differ from the file name. This way the label will simply look more beautiful. To do this, right-click on the shortcut, and in the context menu select “Rename”, and then remove unnecessary words from the name of the file shortcut.

After these steps, you need to open the “Links” folder, to do this you need to follow this path - “Start” menu => “Open a personal folder” => “Links”. Now drag the file shortcut from the folder in which it is currently located to open folder"Links". Immediately after this, a shortcut to the Questions file appears in the Favorites list.

In order to remove added programs and files from the Favorites list, you need to move the mouse cursor over the selected file and select “Delete” in the context menu.

Conclusions of the article

If necessary, the user can add files and folders to the Favorites list in Windows Explorer.

Every day the number of webmasters increases who strive to make their sites equally convenient for users of all browsers, and do not tailor them only for Internet Explorer, as was the case before. Probably most of all users alternative browsers They don’t like the “Add to Favorites” link, which is found on every site, but only works in Internet Explorer. Now I’ll tell you how to implement it correctly on your website this function so that it works in all common browsers.

Since the user may need to add to Favorites not only the site (the main page), but also the page on which he is located, we will consider both options in detail, and you yourself decide which one to use.

Add to Favorites the main page of the site

Let's first look at how the "Add to Favorites" link for Internet Explorer differs from its counterpart in other browsers, and then we will combine them into one. IE uses the window.external.AddFavorite() function, which takes two values: the address of the page to bookmark and its title:

Add site to Favorites

I think there is no need to explain anything here. But we will look at the next example in more detail. The code to add to Favorites for Opera, Firefox and Netscape is as follows:

Add site to Favorites

As you can see, this is a regular link with availability additional parameter rel="sidebar" which just indicates to the browser the need to bookmark the site when you click on the link. In addition, in the title="" parameter you need to indicate with what name to add the site to bookmarks. But the address of the page that is being added is written in href="". Usually indicated home page site and its name.



The window that appears when you click on a link

Now we need to make the "Add to Favorites" link work equally well in all browsers. Since the code for IE only works in it, and the rel="sidebar" parameter is supported only by Opera, Firefox and Netscape, nothing prevents us from simply combining both options into one link:

Add site to Favorites

Let's decide more difficult task and instead of manually entering the address and name of the site, we will automatically determine which page it is on this moment visitor and give him the opportunity to add to Favorites current page with the corresponding address and name.

Add current page to Favorites

So let's start with Internet Explorer again:


As you can see, nothing has changed in the code except the incoming parameters of the window.external.AddFavorite() function. The JavaScript parameter document.title contains the title of the page, which is taken by the browser from the document title we specified, located between the Page Title tags. The browser gets the address of the current page from address bar and assigns it to the location.href parameter. Thus, there is no need to manually change the parameters we need on each page.



New bookmark in Internet Explorer

With Opera, Firefox and Netscape browsers, things are a little more complicated. We will have to write a small JavaScript function that will work in much the same way as the function we already know in Internet Explorer. We'll put it inside the link so it's just one line, but I've formatted it a little to make it easier to read:

Add current page to Favorites

At the very beginning, we assigned the url and title variables the values ​​of the JavaScript parameters window.document.location (page address) and window.document.title (page title). Next we create the bookmark() function. With its help, we generate a link from several variables, the value of which is the address and title of the page. Don't forget also about the rel="sidebar" parameter, which will also be generated using bookmark().

Now we just need to combine the code for Internet Explorer and other browsers to get one cross-browser link:

Add current page to Favorites

We already have a feature that is compatible with major browsers. Now we need to somehow combine it with users.

Breaking stereotypes

Since many users of alternative browsers are already accustomed to the fact that the “Add to Favorites” link only works in Internet Explorer and do not pay attention to it, we need to somehow unobtrusively show the visitor that we have taken care of the functionality of this link in his browser. I think the most successful option would be to determine what browser a visitor to our site is using and display the corresponding logo next to the link. Or you can simply display all the logos at once:


This is what it looks like final result

Copying the article is prohibited.