开发者

External JS usage in FBML - Cannot access external script

I am trying to create a small facebook app and associate it to a fan page in a tab. I am trying to include an external javascript file in my page and call a method on a button click event.

Below is a part of the code

<script language="Javascript" src="http://mysite.com/fb.js"></script>
<input type="button" value="Click....." onClick="javascript:showDialog();" />

content of fb.js is as below

function showDialog() {
    new Dialog().showMessage('Dialog', 'Button clickeed');
}

When I load the tab in my fan page, it shows an error "Cannot allow external script", whereas when I load the canvas url [http://apps.facebook.com/...] directly and click on the button, it works 开发者_开发技巧[shows the dialog].

Does script include works only on the canvas and not on the profile page?

I have another question though Initially I had the script src as a relative path but it errored out with the same error - "Cannot allow external script". Can't I use relative path for the external scripts?


It's bound to be related to the specific behavior of application tabs.

Application tabs are slightly different than canvas pages. When a user first goes to a tab, it is in passive mode. This means applications cannot autoplay Flash or onload JavaScript. Once user interacts with the tab – like clicking the Flash object, the page becomes active, so it can play Flash, execute JavaScript, and so forth.

Looks like for application tabs, it needs to be embedded in the FBML and not an external resource.


Could this not be the problem? http://developers.facebook.com/docs/fbjs

"Most providers who allow developers to embed JavaScript within their domain force developers to use IFrames to sandbox their code. Facebook has taken a different approach to this problem. JavaScript that you give us gets parsed, and any identifiers (function and variable names) get prepended with your application ID."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜