我想直接深层链接到 Facebook iFrame Canvas 中的 GWT 应用程序页面。

第一部分很简单,使用 GWT 的历史标记和 URL,例如:

http://www.example.com/MyApp/#page1

这将在我的应用程序中打开 page1。

Facebook Apps 使用如下应用程序 URL:

http://apps.facebook.com/myAppName

它构建了我的 Canvas 回调 URL

http://www.example.com/MyApp/

有没有办法指定画布回调 url(或书签 url),将用户带到特定页面而不是索引页面?

为什么?你可能会问。除了深层链接的所有好处之外......

  • 我希望“转到应用程序”网址将用户带到带有营销材料的索引页面(画布回调网址)

  • 我希望“书签 URL”将用户(可能返回)带到登录页面并绕过下载营销内容(以及巨大的 SWF 文件)。

有帮助吗?

解决方案

这看起来可能是一个黑客行为,但事实就是如此。

Facebook 允许应用程序将参数附加到 url ?x=123

因此,我检查窗口位置以查看它是否包含我的特殊“页面”参数并加载该页面。鉴于我正在使用 GWT + gwt-presenter 的 PlaceManager 类,下面是我的解决方案。

应用程序深层 url 最终是 http://apps.facebook.com/myAppName?page=page1

    EventBus eventBus = injector.getEventBus();

    // Load PlaceManager so it can start listening
    PlaceManager placeManager = injector.getPlaceManager();
    String currentPlace = History.getToken();

    String place = Window.Location.getParameter( "page" );
    if (place != null && !place.isEmpty()) {
        // send user to the place on the URL line
        eventBus.fireEvent( new PlaceRequestEvent( new PlaceRequest( new Place (place) ) ));

    } else if ("".equals(currentPlace)) {
        // Nothing in URL, load default GWTpage
        eventBus.fireEvent( new PlaceRequestEvent(new PlaceRequest( IndexPresenter.PLACE)));

    } else {
        // fire a body to the Place Manager to activate the requsted Place
        placeManager.fireCurrentPlace();
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top