Converted JavaScript to FBJS - tabs still not working

I tried to convert JavaScript to FBJS according to this page: http://wiki.developers.facebook.com/index.php/FBJS .

However, my tabs still do not work properly. Does anyone have any suggestions on how to fix this, so I can click the tabs and show and hide the content accordingly:

<script type="text/javascript"><!-- var tabLinks = []; var contentDivs = []; function init() { var tabListItems = document.getElementById('tabs').getChildNodes(); for ( var i = 0; i < tabListItems.length; i++ ) { if ( tabListItems[i].getNodeName("LI") ) { var tabLink = getFirstChildWithTagName( tabListItems[i], 'A' ); var id = getHash( tabLink.getAttribute('href') ); tabLinks[id] = tabLink; contentDivs[id] = document.getElementById( id ); } } var i = 0; for ( var id in tabLinks ) { tabLinks[id].addEventListener(onclick, showTab) tabLinks[id].addEventListener(onfocus, function() { this.blur() }; if ( i == 0 ) tabLinks[id].setClassName('selected'); i++;) } var i = 0; for ( var id in contentDivs ) { if ( i != 0 ) contentDivs[id].setClassName('tabContent hide'); i++; } } function showTab() { var selectedId = getHash( this.getAttribute('href') ); for ( var id in contentDivs ) { if ( id == selectedId ) { tabLinks[id].setClassName('selected'); contentDivs[id].setClassName('tabContent'); } else { tabLinks[id].setClassName(''); contentDivs[id].setClassName('tabContent hide'); } } return false; } function getFirstChildWithTagName( element, tagName ) { for ( var i = 0; i < element.getChildNodes().length; i++ ) { if ( element.getChildNodes[i].getNodeName(tagName) ) return element.getChildNodes[i]; } } function getHash( url ) { var hashPos = url.getLastIndexOf ( '#' ); return url.getSubString( hashPos + 1 ); } init(); --></script> 

Thanks for any answer.

+4
source share
2 answers

The FBML tabs (which use FBJS) are deprecated and will now be disabled. You must create a new application with the IFRAME tab (the default is now).

IFRAME tabs are just tabs with an IFRAME inside, and your code is loaded into this iframe from the specified URL like any other web page. You can use any Javascript framework in it (like jQuery), so you don't need to learn to write FBJS.

+1
source

Install the Facebook page that uses the Facebook application . Make sure you set up the application using the iFrame pointing to the file on your server. You will get much more freedom using iFrame when it comes to Javascript, and this is a great way to use CMS if you need to do this too. Best of luck!

0
source

Source: https://habr.com/ru/post/1307285/


All Articles