P.J
P.J

Reputation: 119

HTML- Adding and removing to favorites

I am creating a website and I wanted to know how one would add and remove a page to favorites as I couldn't find much on internet about this. Suppose I have a car page and I have button on the page called add to favorites or an achor (take a pick). I know the way as you can add using the browser code but I want save the car page on my one of my own created page eg.favorite.html and also making sure that I can only add once to the favourite page. So then I can view the favourite list on the page,look through them and remove/clear properties. So i need help with it , please any help would be great. thanks.

add favorite code using a browser, this code save favorites on browser but i want to do it on a page :

  <script type="text/javascript">
$(function() {
    $("#bookmarkme").click(function() {
        // Mozilla Firefox Bookmark
        if ('sidebar' in window && 'addPanel' in window.sidebar) { 
            window.sidebar.addPanel(location.href,document.title,"");
        } else if( /*@cc_on!@*/false) { // IE Favorite
            window.external.AddFavorite(location.href,document.title); 
        } else { // webkit - safari/chrome
            alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != - 1 ? 'Command/Cmd' : 'CTRL') + ' + D to bookmark this page.');
        }
    });
});
</script>

this is achor tag

 <a id="bookmarkme" href="#" rel="sidebar" title="bookmark this page">Save page</a>

above code works to save the page in the browser. I want to add my favorite page on to another html page of mines .

HELP NEEDED!!

Upvotes: 1

Views: 2531

Answers (3)

Martijn Melchers
Martijn Melchers

Reputation: 80

You can make a script that counts the favorites.

Follow these steps to make it work.

Step 1. Create a text file (For example fbp1.txt)
Step 2. Make a PHP Page (For example fbp1.php)
Step 3. Create a page for your blog post (For example Blog1.php)
Step 4. Add this script to the fb1.php file

        <?php
//In the spot of fbp1.txt place your file name!
    $count_my_page = ("fbp1.txt");
    $hits = file($count_my_page);
    $hits[0] ++;
    $fp = fopen($count_my_page , "w");
    fputs($fp , "$hits[0]");
    fclose($fp);
// In the spot of Blog1.php place you page name!
    header("Location : Blog1.php")
    ?>

Step 5. Create your blog post and add these two codes

Code 1:

<img src="/path/to/star.png" href="fbp1.php"/>

Code 2:

<p> <?php echo file_get_contents('fbp1.txt');?> Favorites </p>

When someone clicks the star it add +1 to the text file and it should look like this

[IMAGE OF STAR]
342 Favorites.

I hoped this helped you out!

Upvotes: 1

Martijn Melchers
Martijn Melchers

Reputation: 80

Even tough this is not a question i'll try to answer it..

You can't simply do this by html, javascript.

You need PHP and MYSQL. Try to search google for a simple my favorites script.

What you can do it that you have a counter how many times the favorite button is clicked. Or simple PHP how many people have viewed the post/webpage.

Upvotes: 0

onesvat
onesvat

Reputation: 176

Short, you can't.

When user clicks to add to favorites button, it is not in the scope of the website anymore. Adding favorites or deleting ones are processed in browser side. Only you can do is counting number of clicks to add to favorites button.

Upvotes: 0

Related Questions