简体   繁体   中英

Link to a page within Facebook iframe

Im looking for a way to link to a webpage within a facebook iframe page

so

http://www.facebook.com/designmystyle/app_244351832329915

would be something like

http://www.facebook.com/designmystyle/app_244351832329915?http://www.lickmystyle.com/contact/

I have tried the method here http://www.codingforums.com/archive/index.php/t-85547.html using

    <script type="text/javascript">
    <!--

    function loadIframe(){
    if (location.search.length > 0){
    url = unescape(location.search.substring(1))

    window.frames["app_runner4f84331f0576e6f73380702"].location=url
    }
    }

    onload=loadI

frame
//-->

Im unsure if app_runner4f84331f0576e6f73380702 is the name or the id of the iframe but it was the only one I could find that had a width of 810px by 800px

Any ideas on if this could be done would be great

If it's a facebook canvas app then the url for it should be of apps.facebook.com and not www.facebook.com .

Any querystring parameter that will be added to your canvas app url will be then passed by facebook to your app by adding it to the url of your app when loaded inside the canvas iframe, so if you direct the user to:

apps.facebook.com/app-name?param=value

facebook will POST the app canvas iframe to:

www.yourdomain.com/canvas-path?param=value

Then you can get that parameter like any other GET parameter and what you want with it. One thing though, if that parameter is a url then it should be url encoded, other wise things will go wrong.

What I don't understand is what you're trying to do with the url that you want to pass as a parameter, what is this "app_runner4f84331f0576e6f73380702"?


Edit

Oh, it's a page tab, sorry, I missed that part.

I'v never used it before, but it says in the last section ( Integrating with Facebook APIs ) of the Page Tab Tutorial :

your app will also receive a string parameter called app_data as part of signed_request if an app_data parameter was set in the original query string in the URL your tab is loaded on. For the Shop Now link above, that could look like this: "http://www.facebook.com/YourPage?v=app_1234567890&app_data=any_string_here". You can use that to customize the content you render if you control the generation of the link.

From what I understand, this is exactly what you need in order to get the data.

How ever, you won't be able to change the url of the iframe the way you posted since you have no access to the parent window (your page is on different domain than of facebook, and the browser will prevent it due to the cross-domain policy).

What you can do how ever is just:

document.location.href = URL;

You are in your own page, doesn't matter that it resides in an iframe.

The thing is that you don't need all of that, just be aware in the server side of the parameter that is passed to you from facebook (from the query string) if such exists, and render the page according to that. There's no reason to render a page that then redirects the page to another url, when you already know what the user wants, you're just making the user make a redundant round trip to your server for nothing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM