javascript - Add to favorites button for adding favorite html Pages -
I am creating a mobile website with different events in a specific month. I want to add a button to every event page, When the user is added individually as 'Paste', I want the user to be automatically added to an html page 'Favorites' when the user clicks the Add Favorites Button button.
I would go with a little javascript, called on external and event pages (because many of its examples ). This is actually a very simple process that you are asking about.
- Create a new javascript file named favorite jj
- Save it with this code:
< Strong> Modified to support Opera
Function bookmarks (title, url) {var spath = window.location.pathname; Var sPage = sPath.substring (spath.lastIndexOf ('/') + 1); Url = url + sPage; If (window.sidebar) // firefox window.sidebar.addPanel (title, url, ""); And if (window. Aparea & window.print) {// opera var imil = document.create element ('a'); Elem.setAttribute ('href', url); Elem.setAttribute ('title', title); Elem.setAttribute ('rel', 'sidebar'); Elem.click (); } And if (document.all) // that means window.external.AddFavorite (url, title); }
In the head of every HTML document you write, you must call this script (similar to calling the CSS definition): < P>
& lt; Script src = "** / dir / ** favorites.js" charset = "UTF-8" type = "text / javascript" defer / & gt; & Lt; / Script & gt;
Delete is optional but recommended with a script like this which is not required for the page to work However, if you want users to be able to use bookmarks function before other parts of the page, you can change defer to async .
Now that you are almost there at this point, to save yourself some frustration, make sure that your pages load without error before trying to use a link. This will ensure that there is no bug with your javascript or existing code.
To use to add a favorite button, it is as simple as the use of anchors and links, a link that will specifically use this script:
& lt; A href = "javascript: bookmark ()" & gt; Book me & lt; / A & gt;
or
& lt; A href = "javascript: bookmark ()" & gt; & Lt; Img src = "imgs / bookmarklogo.png" ** other-img-definition-stuffs ** & gt; & Lt; / A & gt;
And in the olden days it was common to use a form button, such as:
Since I really bother myself with HTML / CSS So many years have passed, and at that time, the options have come as if you find this work very difficult, then I have to go with something like that. And I also recommend getting away from handcoding and going to any kind of CMS, like, especially if you are on a tight schedule.
Comments
Post a Comment