954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Errors in Javascript - Quick bit of help needed

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>
hindu times
Junior Poster
125 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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

2. change 336 to either

vsmash
Junior Poster
119 posts since Feb 2010
Reputation Points: 9
Solved Threads: 17
 

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?

hindu times
Junior Poster
125 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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?

hindu times
Junior Poster
125 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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

vsmash
Junior Poster
119 posts since Feb 2010
Reputation Points: 9
Solved Threads: 17
 

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! :)

hindu times
Junior Poster
125 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: