Hey,

Just a quick question. My webpage is all working fine in IE9, new Firefox, Safari, Opera, and Chrome, but in IE7 it's flagging errors to do with the Facebook share buttons (javascript). When you click them nothing shows up.

I was wondering if you could tell me what I may have done wrong. Here's the page that's appearing within a Facebook iframe:
www.rjthompsonmusic.com/facebook/fb_store_music.html

The errors are:

- Line 1013 Character 13 Expected identifier string or number
- Line 336 Character 1 object expected
- Line 416 Character 1 object expected
- Line 513 Character 1 object expected

It looks like they all have something to do with the Facebook code.

Any help would be great.

Many thanks,

Chris

ps.

Here is the code between 995 and 1020 (I've blanked out my app code):

<!--Facebook scripts-->
<div id="fb-root"></div>
      <script src="http://connect.facebook.net/en_US/all.js">
      </script>
<script>
         FB.init({ 
            appId:'my app code', cookie:true, 
            status:true, xfbml:true 
         });

function shareProduct(caption_var, description_var, picture_var) {

         FB.ui({ method: 'feed',  
			link: 'http://www.facebook.com/rjthompsonmusic?sk=app_my app code',
			name: 'RJ Thompson Official Facebook Store',
			caption: caption_var,
			description: description_var,
			picture: picture_var,
            });

}
</script>
<!--end Facebook scripts-->

</body>
</html>

And here is the code for line 336 (I'm assuming the other errors are just duplicated of this):

<a href="#" onclick="javascript:shareProduct('A Better Life (Extended Version) - Digital Download', 'RJ Thompsons &quot;A Better Life (Extended Version)&quot; available for Digital Download from his Facebook Store. Includes the single, two remixes and the music video. Only &pound;1.99!', 'http://www.rjthompsonmusic.com/facebook/a_better_life_270.jpg')">
Facebook</a>

Two things:
1. use escape and unescape to make sure your strings don't contain dodgy characters.

2. change 336 to either
<a href="#" onclick="shareProduct('A Better life... bla bla - removing the "javascript:"
or
<a href="javascript:shareProduct('A Better life.... bla bla

"javascript:" is only used in the quoted href.
See how you go from those changes.

Thanks for the reply. I've changed all of the javascripts which hasn't affected anything. I'm not sure what you mean by escape and unescape, but is there anything in that first bit of code that you think could be causing a problem?

Right, I've changed the Javascripts to read href="#" onclick="shareProduct...

And I've also spotted a comma at the end of picture_var that i have removed. It isn't throwing the errors in IE7 anymore but it is still not loading the script. If you right click and open in a new window however, it opens. Any ideas?

escape and unescape are javascript functions - google them for full definitions;

to determine if the script is being loaded stick an alert('foo'); on the first line of the function;
if you get the alert, the script is being loaded. After that, move the alert down past each line and test to see if/where the function is exiting;
if your function is loading and running through properly, you might find that the fb login window is behind your browser, or that you are already logged into fb

Hey. Thanks for this tip. Right... I added the alert to the beginning of the script, and in all browsers the alert showed up when you click Share On Facebook. I then pasted the alert to the end of the script. Bizarelly, the alert still displayed before the Facebook script in all browsers bar IE7. In IE7 the alert did show here too but still no Facebook script.

Confused! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.