Execute Javascript when Facebook crawls website

血红的双手。 提交于 2019-12-31 05:34:21

问题


I use javascript function below to move embed Facebook Meta data to head, This works fine for visitors but not when FB crawls the page, How can i execute this when Facebook crawling the page ?

function metaBodyToHead() {

    var head = document.head,
        metaTAGs = document.getElementsByTagName( "DIV" );

    for( var i = 0, ln = metaTAGs.length; i < ln; i++ ) {

        head.appendChild( metaTAGs[ i ].parentNode.removeChild( metaTAGs[ i ] ) );
    }
}

metaBodyToHead();

I need to get the meta data in head when facebook crawls the page

Test page: http://greenboxmedia.org/meta.html

Facebook debug: https://developers.facebook.com/tools/debug/og/object?q=www.greenboxmedia.org%2Fmeta.html


回答1:


How can i execute this when Facebook crawling the page ?

Not at all, of course.

Facebook’s scraper just looks at the HTML code of your page; it’s not a full-fledged “browser” that would execute any client site code.

You’ll have to put your OG meta data into the HTML code that get’s delivered when the URL is requested. That’s how it works.



来源:https://stackoverflow.com/questions/11592102/execute-javascript-when-facebook-crawls-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!