Dez
February 2, 2018, 9:05am
1
Hi, can anyone see any issues here please? I thought I had it just right, but it still brings up errors.
<?php
function() ;
$('#bookmarkme').click(function() {
if (window.sidebar && window.sidebar.addPanel) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(document.title, window.location.href, '');
} else if (window.external && ('AddFavorite' in window.external)) { // IE Favorite
window.external.AddFavorite(location.href, document.title);
} else if (window.opera && window.print) { // Opera Hotlist
this.title = document.title;
return true;
} else { // webkit - safari/chrome
alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL') + ' + D to bookmark this page.');
}
});
});
?>
<a id="bookmarkme" href="#" rel="sidebar" title="bookmark this page">Bookmark This Page</a>
chorn
February 2, 2018, 10:07am
2
If you get errors, why don’t you say which? Why don’t you fix them?
Dez
February 2, 2018, 10:18am
3
chorn:
Why don’t you fix them?
Errr, can you guess why the post was made?
Gandalf
February 2, 2018, 10:21am
4
You could still tell us what errors you are getting.
1 Like
Dez
February 2, 2018, 10:24am
5
That’s correct, I didn’t know if someone could see the issue straight away. Will post errors in a few moments.
Dez
February 2, 2018, 10:28am
6
Parse error: syntax error, unexpected ';', expecting '{' in /home/shom/public_html/page/index.php on line 2
Hi there Dez,
Which begs the question: why are you bothering with this ?
All modern browsers have the “Bookmark this Page ” option.
Assuming that it is just a coding exercise, try it like this…
<script>
(function(w,d) {
'use strict';
$('#bookmarkme').click(function() {
if (w.sidebar && w.sidebar.addPanel) { // Mozilla Firefox Bookmark
w.sidebar.addPanel(d.title, w.location.href, '');
} else if (w.external && ('AddFavorite' in w.external)) { // IE Favorite
w.external.AddFavorite(location.href, d.title);
} else if (w.opera && w.print) { // Opera Hotlist
this.title = d.title;
return true;
} else { // webkit - safari/chrome
alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL') + ' + D to bookmark this page.');
}
});
}(window, document));
</script>
coothead
Dez
February 2, 2018, 10:45am
8
Which begs the question… Err, here is where we try to help each other, but no worries, thank you for the help on the code.
Surely the error message pretty much tells you the line with the problem is here:
function() ;
and it says why it’s a problem.
What’s puzzling me is why the PHP tags just seem to contain JavaScript, no PHP at all.
1 Like
Dez
February 2, 2018, 10:48am
10
It stated the line, but not the actual issue.
Surely the first section of the error message
Parse error: syntax error, unexpected ';', expecting '{'
describes the issue? You have a ‘;’ where it expects a ‘{’.
It’s not always that clear with parse errors as a general imbalance of braces can sometimes only be detected miles away from the actual line that breaks it. But this seems fairly clear.
1 Like
Dez
February 2, 2018, 10:50am
13
Yep, and if it was clear to me, I sure wouldn’t have posted. I’ll try the suggestion and hope everyone has a good day!
One thing I tend to do with braces is run down through the code that presents the issue and keep a mental count - add one every time an open-brace appears, subtract one when a close-brace appears. In your original code the end result is -1 which indicates you’ve closed more than you opened.
1 Like
Dez:
Which begs the question… Err, here is where we try to help each other, but no worries, thank you for the help on the code.
Yes, we help each other with code here, but a more important assistance is in recommending correct courses of action to take.
It is a bad practice to use scripting to set a bookmark for the page. We’ve been recommending against the practice for over ten years now.
1 Like
Dez
February 2, 2018, 10:59am
16
It’s worked very well for me in the past, so I see no reason to drop it.
Anyways, lets move on.
system
Closed
May 4, 2018, 5:59pm
17
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.