Thursday 6 January 2011

Change iframe src attribute in Facebook applications

Sometimes it is necessary to change source of the iframe on facebook applications dynamically. In Facebook applications iframe can be created only using tag "fb:iframe" and Facebook doesn't allow access to iframe attributes. Of course we can create a set of fb:js string variables for all cases that we need. But it is not very good solution.

One of the solutions that can be used looks as follows.

At first create iframe using fbml:
<fb:js-string var="iframe_element">
  <fb:iframe id="fb-iframe" src="http://your.iframe.location" />
</fb:js-string>

Than we should have an html element that will be a container for iframe:
<div id="iframe-block"> </div>
Next step is to display iframe. This can be done using fbml method setInnerFBML:
document.getElementById('iframe-block').setInnerFBML(iframe_element);
After this we can get access to iframe attributes.
document.getElementById('view-iframe-element').setSrc('http://your-new-url');
So, the only way to change the src of iframe that I could find is to display the iframe and the change it attribute src.

1 comment:

  1. Casino - A place to go to getaway if you can't make it back
    Casino. The Aussie's ultimate 경주 출장샵 in 양산 출장안마 luxury resort destination. 고양 출장마사지 Located in Las Vegas Strip, Aussie's 의왕 출장안마 Aussie casino hotel & casino 대전광역 출장마사지 is within the

    ReplyDelete