Jump to content

Bookmark in Chrome still doesn't work in latest Prestashop


Hasini

Recommended Posts

OK so i've been trying to click the "add to favorites" button on the main page of my Presta, and it isn't working. I am using Chrome browser.

I tried with IE and it works.

 

I check the "Elements" in Chrome, and in the Js/tools.js, there is a "mistake":

 

Uncaught TypeError: Object #<Object> has no method 'AddFavorite'

 

return window.external.AddFavorite( url, title);

 

Uncaught TypeError: Object #<Object> has no method 'AddFavorite' (repeated 5 times)

else if (window.opera && window.print)

 

(repeated 5 times, because i tried to click it 5 times.)

 

How do i fix it please?

Link to comment
Share on other sites

Hi.

 

Google Chrome does not allow adding bookmarks from Javascript, for security reasons.

 

Here's a function that could help you:

function add_bookmark(url,page_title) { if(window.sidebar) // Firefox / Mozilla { window.sidebar.addPanel(page_title, url,''); } else if(window.opera) // Opera { var a = document.createElement('A'); a.rel = 'sidebar'; a.target = '_search'; a.title = page_title; a.href = url; a.click(); } else if(window.external) // Inept Exploiter { window.external.AddFavorite(url, page_title); } else { alert(' Your web browser appears to not support adding a bookmark via Javascript. Please manually add one via your browser's bookmark menu. '); } }

 

If the browser does not support adding bookmark by Javascript, the user will be notified to add it manually.

 

Regards.

 

Robin.

 

The CartExpert Team

  • Like 1
Link to comment
Share on other sites

Hi.

 

Google Chrome does not allow adding bookmarks from Javascript, for security reasons.

 

Here's a function that could help you:

function add_bookmark(url,page_title) { if(window.sidebar) // Firefox / Mozilla { window.sidebar.addPanel(page_title, url,''); } else if(window.opera) // Opera { var a = document.createElement('A'); a.rel = 'sidebar'; a.target = '_search'; a.title = page_title; a.href = url; a.click(); } else if(window.external) // Inept Exploiter { window.external.AddFavorite(url, page_title); } else { alert(' Your web browser appears to not support adding a bookmark via Javascript. Please manually add one via your browser's bookmark menu. '); } }

 

If the browser does not support adding bookmark by Javascript, the user will be notified to add it manually.

 

Regards.

 

Robin.

 

The CartExpert Team

 

That's a good tip but don't you think you should say where to place the line so those with a little less experience can figure it out.

Link to comment
Share on other sites

Nice.

 

 

I personally think this bookmark function is obsolete.

 

I do always remove this from my sites.

 

It's much more important having good SEO techniques so that the customers can find your shop on google than having bookmark button.

 

Bookmarking and SEO is not the same. It is more comfortable to bookmark a site/page, than to search for it all over again.

  • Like 1
Link to comment
Share on other sites

Hi.

 

Google Chrome does not allow adding bookmarks from Javascript, for security reasons.

 

Here's a function that could help you:

function add_bookmark(url,page_title) { if(window.sidebar) // Firefox / Mozilla { window.sidebar.addPanel(page_title, url,''); } else if(window.opera) // Opera { var a = document.createElement('A'); a.rel = 'sidebar'; a.target = '_search'; a.title = page_title; a.href = url; a.click(); } else if(window.external) // Inept Exploiter { window.external.AddFavorite(url, page_title); } else { alert(' Your web browser appears to not support adding a bookmark via Javascript. Please manually add one via your browser's bookmark menu. '); } }

 

If the browser does not support adding bookmark by Javascript, the user will be notified to add it manually.

 

Regards.

 

Robin.

 

The CartExpert Team

 

I tried this today, I tried to add to tools.js did not work, I tried to replace the similar code in tools.js did not work, no matter what way I inserted it did not work, it would actually make the bookmark disappear.

Prestashop 1.4.7

Link to comment
Share on other sites

Bookmarking and SEO is not the same. It is more comfortable to bookmark a site/page, than to search for it all over again.

 

I have to agree, a bookmark button is easy to use, and it gives people a push to make themselves your returning customers ($$$).

Good SEO is very important but they don't really contradict each other.

Link to comment
Share on other sites

If you do not have the coding skills to do this; you are welcome to buy our coding time

 

 

I know exactly where to put the code but I thought you might like to reply, anyway it does not work, as you can see from my post above I tried several methods and could not get your code to work.

 

 

For those of you interested here is something that does work with both 1.4 and 1.5.

 

Change the following code in tools.js located in the js folder:

 

Change this at line 141:

 

function writeBookmarkLinkObject(url, title, insert)

{

if (window.sidebar || window.external)

return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + escape(title) + '\')">' + insert + '</a>');

else if (window.opera && window.print)

return ('<a rel="sidebar" href="' + escape(url) + '" title="' + escape(title) + '">' + insert + '</a>');

return ('');

}

 

To this:

 

function writeBookmarkLinkObject(url, title, insert)

{

if (window.navigator.userAgent.indexOf('Chrome') != -1)

return ('<a href="#" class="bookmark_chrome">'+ insert +'<span>Google Chrome Users </br>Press "Ctrl + D" to add to favorites</span></a>');

if (window.sidebar || window.external)

return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + escape(title) + '\')">' + insert + '</a>');

else if (window.opera && window.print)

return ('<a rel="sidebar" href="' + escape(url) + '" title="' + escape(title) + '">' + insert + '</a>');

return ('');

}

 

Now add the following to Blockpermanentlinks.css

 

in 1.4 add this to blockpermanentlinks.css located in ..themes/yourtheme/css/modules/blockpermanentlinks/

 

In 1.5 add to blockpermanentlinks.css located in ..modules/blockpermanentlinks

 

.bookmark_chrome span {

width:130px;

padding:5px;

background:#C0C0C0;

color:#000;

box-shadow:1px 1px 2px #ccc;

position:absolute;

/* Modify this for your template design*/

top:15px;

z-index:999;

display:none

}

.bookmark_chrome:hover span { display:block}

 

 

 

Here is a pic of what you will get when you mouse over the bookmark icon:

 

  • Like 1
Link to comment
Share on other sites

I know exactly where to put the code but I thought you might like to reply, anyway it does not work, as you can see from my post above I tried several methods and could not get your code to work.

 

 

For those of you interested here is something that does work with both 1.4 and 1.5.

 

Change the following code in tools.js located in the js folder:

 

Change this at line 141:

 

function writeBookmarkLinkObject(url, title, insert)

{

if (window.sidebar || window.external)

return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + escape(title) + '\')">' + insert + '</a>');

else if (window.opera && window.print)

return ('<a rel="sidebar" href="' + escape(url) + '" title="' + escape(title) + '">' + insert + '</a>');

return ('');

}

 

To this:

 

function writeBookmarkLinkObject(url, title, insert)

{

if (window.navigator.userAgent.indexOf('Chrome') != -1)

return ('<a href="#" class="bookmark_chrome">'+ insert +'<span>Google Chrome Users </br>Press "Ctrl + D" to add to favorites</span></a>');

if (window.sidebar || window.external)

return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + escape(title) + '\')">' + insert + '</a>');

else if (window.opera && window.print)

return ('<a rel="sidebar" href="' + escape(url) + '" title="' + escape(title) + '">' + insert + '</a>');

return ('');

}

 

Now add the following to Blockpermanentlinks.css

 

in 1.4 add this to blockpermanentlinks.css located in ..themes/yourtheme/css/modules/blockpermanentlinks/

 

In 1.5 add to blockpermanentlinks.css located in ..modules/blockpermanentlinks

 

.bookmark_chrome span {

width:130px;

padding:5px;

background:#C0C0C0;

color:#000;

box-shadow:1px 1px 2px #ccc;

position:absolute;

/* Modify this for your template design*/

top:15px;

z-index:999;

display:none

}

.bookmark_chrome:hover span { display:block}

 

 

 

Here is a pic of what you will get when you mouse over the bookmark icon:

 

That was a snippet for inspirational purposes. Next time try to reply to the question and not criticize.

 

Regards.

 

Robin.

 

The CartExpert Team

Link to comment
Share on other sites

Hey people, i appreciate all the help given, but nothing works.

 

Tried tdr170's method, but still didn't work.

 

----------------

 

I am getting a red highlight error on the line "return false;", in js/tools.js

 

if (typeof customizationFields != 'undefined')

for (var i = 0; i < customizationFields.length; i++)

/* If the field is required and empty then we abort */

if (parseInt(customizationFields[1]) == 1 && ($('#' + customizationFields[0]).html() == '' || $('#' + customizationFields[0]).html() != $('#' + customizationFields[0]).val()) && !pattern.test($('#' + customizationFields[0]).attr('class')))

return false;

return true;

}

Edited by Hasini (see edit history)
Link to comment
Share on other sites

Hi Hasini.

 

Use this function, this will work with all browsers. You can just overwrite the function addBookmark in tools.js

 

function addBookmark(url, title)
{
if($.browser.mozilla)
{
 window.sidebar.addPanel(title, url,'');
}
else if($.browser.opera)
{
 var a = document.createElement('A'); a.rel = 'sidebar'; a.target = '_search'; a.title = title; a.href = url; a.click();
}
else if($.browser.msie)
{
 window.external.AddFavorite(url, title);
}
else
{ alert(' Your web browser appears to not support adding a bookmark via Javascript. Please manually add one via your browsers bookmark menu. '); }

}

 

Regards.

 

Robin.

 

The CartExpert Team

  • Like 1
Link to comment
Share on other sites

Hi Hasini. Use this function, this will work with all browsers. You can just overwrite the function addBookmark in tools.js
 function addBookmark(url, title) { if($.browser.mozilla) { window.sidebar.addPanel(title, url,''); } else if($.browser.opera) { var a = document.createElement('A'); a.rel = 'sidebar'; a.target = '_search'; a.title = title; a.href = url; a.click(); } else if($.browser.msie) { window.external.AddFavorite(url, title); } else { alert(' Your web browser appears to not support adding a bookmark via Javascript. Please manually add one via your browsers bookmark menu. '); } } 

Regards. Robin. The CartExpert Team

 

Thank you man, seriously, now it worked, after i found out I was supposed to change the MAIN tools.jr and not the one in my theme.

 

But this is very weird\annoying.

It appears that there is an identical script in both about this bookmark!

what is that all about???

Link to comment
Share on other sites

  • 4 months later...

OK so i've been trying to click the "add to favorites" button on the main page of my Presta, and it isn't working. I am using Chrome browser.

I tried with IE and it works.

 

I check the "Elements" in Chrome, and in the Js/tools.js, there is a "mistake":

 

Uncaught TypeError: Object #<Object> has no method 'AddFavorite'

 

 

return window.external.AddFavorite( url, title);

 

 

chrome-devtools://devtools/Images/errorIcon.pngUncaught TypeError: Object #<Object> has no method 'AddFavorite' (repeated 5 times)

else if (window.opera && window.print)

 

(repeated 5 times, because i tried to click it 5 times.)

 

How do i fix it please?

 

 

alternative ways without changing the function :

Press "Ctrl-D".

In order for all visitors to see, change the title "bookmark" to "bookmark (Ctrl-D)".

How to edit the file "/ modules / blockpermanentlinks / blockpermanentlinks-header.tpl": (in line 31)

 

 

<li id="header_link_bookmark">

<script type="text/javascript">writeBookmarkLink('{$come_from}', '{$meta_title|addslashes|addslashes}', '{l s='bookmark' mod='blockpermanentlinks' js=1}');</script>

</li>

 

 

change this :

 

 

<li id="header_link_bookmark">

<script type="text/javascript">writeBookmarkLink('{$come_from}', '{$meta_title|addslashes|addslashes}', '{l s='bookmark(Ctrl-D)' mod='blockpermanentlinks' js=1}');</script>

</li>

 

Regards

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...