How can a canvas app redirect to another tab such as the Wall? - facebook-iframe

I'm trying to create a so-called "Welcome Tab" app for a business page. What I want to happen is that either my canvas app displays a message when a vistor hasn't Liked the page, or the normal "Wall" tab when they have.
I've done this by setting my canvas page as the default landing tab and then checking the 'liked' parameter passed by Facebook and my PHP can successfully deterime what it should be doing. As per this extract:
if ($results['page']['liked'] == 1) {
$redirect = $pages[$results['page']['id']]['liked']; } else {
$redirect = $pages[$results['page']['id']]['unliked']; }
header('Location: '.$baseurl.$redirect);
However using header() to load a page which in turn contains a little bit of Javascript to do a "top.location = http://www.facebook.com/pages/xxxxxxx/yyyyyyy?sk=wall" redirection takes a second or so and results in the visitor seeing a blank canvas page briefly and then a full page reload.
However this page https://www.facebook.com/ourcarnoustie seems to be able to instantly display the Wall to Likers, and its own "Welcome" tab to non-Likers without any apparent delay or refresh.
Any suggestions or pointers would be greatly appreciated. Thanks.

Facebook defaults to the wall for people who've liked the page. In fact it's usually the reverse that's requested on how to set the welcome page for everyone :)
For what you're asking you shouldn't need to do anything as that's the behavior.

Hmmm this is funny you posted this cause I've just landed myself with the same issue today.
I'm using this php currently to change my html between 'liked' and 'not liked...
<?php
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["page"]["liked"])) {
//echo 'UNLIKED';
} else {
//echo 'USER HAS LIKED';
}
?>
But I also need to find away some how for the users that have already liked the page, to be redirect to the wall - instead of seeing the welcome app.
Because it's inside an iframe, do you think it's possible?
I also looked at that facebook page with welcome app that you said works, and it does work so must be possible unless its an older app that's not using a iframe to pull in the content.

I've found the answer to my own question.
The Facebook Pages FAQ includes this statement:
Why can't I choose a landing tab for existing followers of my Page?
The default landing tab can only be adjusted for people that are not following your Page. Once they follow your Page, they will see the Page's wall as the default.
So people who LIKE the page are automatically taken to the Wall page regardless of the landing tab selected in the Page settings. Therefore the landing tab app doesn't have to do any of the redirection I have been trying to figure out as Facebook already does it anyway!

Related

CefSharp3 Can't navigate back

I am currently using CefSharp.MinimalExample.Wpf (CEF branch 1750 and CefSharp 33.0.0) to evaluate my issue. I just added a button to the MainView.xaml like this <Button Command="{Binding WebBrowser.BackCommand}">Back</Button>. The buttons enable state is updated on loading a site (once the site is loaded it is pressable). But clicking on it doesn't work to navigate back.
My second approach was to execute a java script snippet on click browser.ExecuteScriptAsync("history.back()"); But this doesn't work either.
Any ideas?
I have the same problem, but your answer gave me an idea, I hope my solution works for you.
The first page showed by the browser is like a blank page, so, when this blank page is loaded, I assign the URL, through FrameLoadEnd event of the browser.
I have a flag to avoid assign the URL more than one time.
Browser.FrameLoadEnd += delegate
{
if (!flag)
{
Browser.Address = "http://www.google.com.mx";
flag = true;
}
};
Looks like with this the problem is solved.
My investigation result is that if you set the URL too early - on creation of the browser object ChromiumWebBrowser until up to about 250ms (try&error value on my machine) - at least the back-function and JavaScript-injection won't work. The Initialized event is not a solution because it is too early. Apart from this the site will be rendered fine and you can browse the web. This was the part which distracted me and let me search elsewhere.

Backbone.js change url without reloading the page

I have a site that has a user page. On that page, there are several links that let you explore the user's profile. I'd like to make it so that, when one of those links is clicked on, the url changes, but the top third of the page containing the user's banner doesn't reload.
I'm using Backbone.js
I have a feeling that I'm in one of those situation where I have such a poor understanding of the problem I'm dealing with that I'm asking the wrong question, so please let me know if that appears to be the case
My mistake was assuming that there was a special, built-in way of doing this in backbone. There isn't.
Simply running the following line of code
window.history.pushState('object or string', 'Title', '/new-url');
will cause your browser's URL to change without reloading the page. You can open up the javascript console in your browser right now and try it with this page. This article explains how it works in more detail (as noted in this SO post).
Now I've just bound the following event to the document object (I'm running a single page site):
bindEvents: () ->
$(document).on('click', 'a', #pushstateClick)
pushstateClick: (e) ->
href = e.target.href || $(e.target).parents('a')[0].href
if MyApp.isOutsideLink(href) == false
if e.metaKey
#don't do anything if the user is holding down ctrl or cmd;
#let the link open up in a new tab
else
e.preventDefault()
window.history.pushState('', '', href);
Backbone.history.checkUrl()
See this post for more info.
Note that you CAN pass the option pushstate: true to your call to Backbone.history.start(), but this merely makes it so that navigating directly to a certain page (e.g. example.com/exampleuser/followers) will trigger a backbone route rather than simply leading to nowhere.
Routers are your friend in this situation. Basically, create a router that has several different routes. Your routes will call different views. These views will just affect the portions of the page that you define. I'm not sure if this video will help, but it may give you some idea of how routers interact with the page: http://www.youtube.com/watch?v=T4iPnh-qago
Here's a rudimentary example:
myapp.Router = Backbone.Router.extend({
routes: {
'link1': 'dosomething1',
'link2': 'dosomething2',
'link3': 'dosomething3'
},
dosomething1: function() {
new myapp.MyView();
},
dosomething2: function() {
new myapp.MyView2();
},
dosomething3: function() {
new myapp.MyView3();
}
});
Then your url will look like this: www.mydomain.com/#link1.
Also, because <a href=''></a> tags will automatically call a page refresh, make sure you are calling .preventDefault(); on them if you don't want the page to refresh.

Backbone.js: Disallow backbone history

I came on this site to research a problem that I've been having regarding negating Backbone.js's history for certain elements. Thankfully, I came across this answer: here.
While it had provided a solution for me, the ultimate result was partial.
PROBLEM:
I am using Backbone.js for my navigation. I navigate to a route called "Portfolio" and then a number of images show up which can then be clicked again to view information. In order to render this information, I have it going through another route. The aforementioned resolution had me assigning the following code to negate these Portfolio links from being part of the History:
$(this).bind('click', function(e){
theSiteController.navigate('portfolio/portfolioSelection/' + i, {trigger:true, replace: true });
});
I had applied replace: false to the .navigate and it worked: whenever I hit the Back button, I would skip back to the origin page that I came from. HOWEVER, when I hit the Forward button in my browser, it points me back to the Portfolio link that I had clicked before, which looks like this:
#portfolio/portfolioSelection/4
I have it set to a different View, so I'm wondering if that has something to do with it.
QUESTION:
When I click the Forward button in my browser, how would I re-route it so that way it goes to
#portfolio
instead of
#portfolio/portfolioSelection/4
To view the site, please click here.
I apologize if this has been answered, but I can't seem to find a proper resolution.
Thank you, in advance, for your help!

Backbone.js: How to utilize router.navigate to manipulate browser history?

I am writing something like a registration process containing several steps, and I want to make it a single-page like system so after some studying Backbone.js is my choice.
Every time the user completes the current step they will click on a NEXT button I create and I use the router.navigate method to update the url, as well as loading the content of the next page and doing some fancy transition with javascript.
Result is, URL is updated which the page is not refreshed, giving a smooth user experience. However, when the user clicks on the back button of the browser, the URL gets updated to that of a previous step, but the content stays the same. My question is through what way I can capture such an event and currently load the content of the previous step and present that to the user? Or even better, can I rely on browser cache to load that previously loaded page?
EDIT: in particular, I'm trying something like mentioned in this article.
You should not use route.navigate but let the router decide which form to display based on the current route.
exemple :
a link in your current form of the registration process :
<a href="#form/2" ...
in the router definition :
routes:{
"form/:formNumber" : "gotoForm"
},
gotoForm:function(formNumber){
// the code to display the correct form for the current url based on formNumber
}
and then use Backbone.history.start() to bootstrap routing

CakePHP Logs Me Out Prematurely

I have a CakePHP app that seems to be terminating my session on one specific action. I have a page which, when a link is clicked, launches a Fancybox overlay of the iframe type. In that overlay, the user fills out and submits a form. The form is submitted properly, does its work (including sending an email), loads the success view and lets me close the overlay, but as soon as I try to get to any other page, I'm sent to the login screen to reauthenticate.
The value of my Security.level config setting is medium and my Session.timeout is 120, so that shouldn't be the problem. Anyone have any idea what could be creating this?
Thanks.
is it possible that your ajax calls and redirects are not going to the same place, eg www.site.com and site.com? I have had that before and also kept getting logged out.
So this wasn't fun to track down, but it was me being an idiot. Buried in the code was some early-stage code to refresh user data in the authenticated session that wasn't doing what it should have been doing. It was attempting to update the entire Auth.User object directly (e.g. $this->Session->write( 'Auth', $user )) instead of calling the login method.
Once I changed the Session::write() code to $this->Auth->login( $user ), everything lined up nicely. A nice bit of reference material on this subject at http://milesj.me/blog/read/31/Refreshing-The-Auths-Session.

Resources