First up, apologies for my non-technical-ness. I've looked and looked for an answer to this, but had no luck.
My site has a FB App for the purposes of grabbing the auth token so people can share stuff they create on my site right to their FB wall. The app just lets the site grab the token so we don't need to ask people to login to FB over and over.
On FB we have a canvas page to go with this app, but all it does is load our webpage in an iFrame on it (and it looks sorta crappy there).
Is there a way to change the Canvas Page to our FB Fan Page? This way if people click on our "app" from their own wanderings about FB they'll be directed to a FB fan page rather than our page looking weird in FB.
Again, I apologize if this question is way simple. I'm new. If someone has an answer for me and could use puppets to explain-- that'd probably help.
Thanks so mcuh!
This is an obnoxious method but you can redirect the visitors to your Facebook Page when your Canvas Page is loading by checking the URL.
First you have a function that gets the URL of your Canvas Page.
function checkPage()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on")
{
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80")
{
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else
{
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
Then you check if the URL contains "fb_source" which appears in every Canvas Page, if it does then you redirect them to your desired location.
$currentUrl = checkPage();
if(strpos($currentUrl,'fb_source') !== false)
{
<script type="text/javascript">
top.location.href = "URL HERE";
</script>
}
Related
What I am trying to achieve is to find a way of displaying a wiki page content in a floating iFrame ( and of course keep the styling ) for a tool that I am developing for our employees. Right now the tool I made is using jQuery dialog box to display a specific document / pdf, For compatibility and usability purposes I would really like to upgrade that so it uses a wiki page instead of documents / PDFs.The problem that I am facing is that there is no really direct link to the content of a Sharepoint wiki page instead the only available direct link is the one to the page all together with all the navigation menus, option panel, user panel etc. I want to avoid using javascrip to strip away these elements. Instead I am simply trying to find out if sharepoint 2013 has some more elegant way of providing the content such as: Web service or javascript SP API.
My ideas so far:
REST Url to give the content back? I know for sure it works for lists and libraries but I couldn't find anything in the REST API About wiki page content
SP.js ? Couldn't find anything about that either
Anyways, it could be possible that I have overlooked things, or probably haven't searched hard enough. However, any help is very very welcome. If you don't know about a concrete solution I would be very happy with nice suggestions too :)
If there is nothing out of the box I will have to get to my backup plan of a jQuery solution to get the page and strip off all unnecessary content and keep the styling.
I believe you are on the right track with REST API, in Enterprise Wiki Page the content is stored in PublishingPageContent property.
The following example demonstrates how to retrieve Enterprise Wiki Page content:
var getWikiPageContent = function (webUrl,itemId,result) {
var listTitle = "Pages";
var url = webUrl + "/_api/web/lists/GetByTitle('" + listTitle + "')/items(" + itemId + ")/PublishingPageContent";
$.getJSON(url,function( data ) {
result(data.value);
});
}
Usage
getWikiPageContent('https://contoso.sharepoint.com/',1,function(pageContent){
console.log(pageContent);
});
And something for those of you who like to have more than one different examples:
var inner_content;
var page_title = "home";
$.ajax({
url: "https://mysharepoint.sharepoint.com/MyEnterpriseWikiSite/_api/web/Lists/getbytitle('Pages')/items?$filter=Title eq '" + page_title +"'",
type: "GET",
headers: {
"ACCEPT": "application/json;odata=verbose"
},
success: function (data) {
if (data.d.results[0]) {
inner_content = data.d.results[0].PublishingPageContent;
}
},
error: function(){ //Show Error here }
});
That's what did the job for me.
This example fetches the inner content of an Enterprise wiki page by Title( make sure you are not using the Name of the page, although Title and Name can be given the same string value, they are different fields in sharepoint 2013 )
I am trying to solve an issue with modals. What I want to do is allow the user to click the browser's back button to dismiss a modal and return to the original state of the page, this is: without modal. For such purpose I thought about using HTML 5 history API.
I started trying to append a querystring parameter to the URL, such as http://...page.html?show_modal=[yes|no] but I ended leaving this approach because I couldn't handle all the stuff involving popstate event, pageshow event, etc. I couldn't make it work and it overwhelmed me.
Then I tried with a more simple approach involving a hash appended to the URL, such as http://...page.html#modal, and the hashchange event. This approach is working better for me and I almost have it.
When the user clicks the button to show the modal, he or she can click the browser's back button and it will dismiss the modal. Furthermore, after that, the user can click the browser's forward button and it will show the modal again. Very nice! The user can also navigate directly to the URL with the hash to access directly this state of the page, as well as he or she can bookmark such state of the page. It's working pretty neat and I'm rather happy with the results.
The problem is that it is not working totally perfect. When the user dismiss the modal by clicking the background, the ESC key or the X in the upper right corner, the history starts to mess up. Try it: open the modal by clicking on the button, then click the background to dismiss it (look a the URL in the address bar, first problem here is that the hash isn't removed), then click your browser back button and you will see it isn't working correctly. You will end with a duplicate in your history and you have to click the back button twice in order to go to the previous page. This is not desirable from an UX viewpoint. Does anyone know a solution to this?
I provide my code in this CodePen and at the end of this question. I suggest trying it in your own machine and NOT IN Codepen, so you can view the hash in the URL, etc. Also, it doesn't work in Codepen Full mode, I don't know why.
Thanks!!
I am using Foundation 5.2.1
HTML
<div class="row">
<div class="small-12 columns">
<h1>Reveal Modal</h1>
<h2>Manipulation of the browser history for a better UX</h2>
<a class="button radius" href="#" data-reveal-id="sampleModal" id="button">Show Modal...</a>
</div>
</div>
<!-- ############# -->
<!-- MODAL -->
<!-- ############# -->
<div id="sampleModal" class="reveal-modal medium" data-reveal>
<h2>Hi!</h2>
<p>You may think you are on a new page now, but you aren't. Try to click your browser <kbd>Back</kbd> button to dismiss this modal and return to the the page you were viewing.</p>
<a class="close-reveal-modal">×</a>
</div>
JavaScript
function setModalHash(url, present) {
var a = $('<a>', { href:url } )[0]; // http://tutorialzine.com/2013/07/quick-tip-parse-urls/
var newHash = "";
if (present === true) {
newHash = "#modal";
}
// Build the resulting URL
result = a.protocol + "//" + a.hostname + ":" + a.port + a.pathname + a.search + newHash;
return result;
}
$("#button").on('click', function() {
history.pushState(null, null, setModalHash(document.URL, true));
});
$(window).on("hashchange load",function(e) {
// Handling also the load event allows navigation directly to http://host/path/to/file#modal and bookmarking it
if (document.location.hash == "#modal") {
$("#sampleModal").foundation("reveal","open");
}
else {
$("#sampleModal").foundation("reveal","close");
}
});
I've been messing with the history api/History.js in combination with session storage to maintain modal state, and open/close based upon user navigation. I've finally achieved about 90% of my goal, but history is implemented very poorly in Safari and iOS Safari so remove the features for these browsers.
Some of the problems you may be running into with the hash approach is that when you use the # with pushstate it actually doesn't push a new object into the history state. It sometimes seems to push history onto the stack and you could use history.back() to fire a popstate, but if you were to say refresh the page with your hashurl and do some sort of check for hash on page initiation, there doesn't seem to be a new history pushed onto the stack, and therefore on backwards navigation the user will leave the site rather than closing the modal.
Here is my implementation working for all browsers except for where it falls back to normal behavior is Safari:
http://dtothefp.github.io/hosted_modal_history_sample/
https://github.com/dtothefp/html5history_express_modal_toggle
Like I said I use History.js in combination with sessionstorage because annoyingly enough, in the popstate for closing the modal the history object is removed, which is exactly when I would need it. In all a very poorly implemented API.
I don't change the URL because this project does not have a backend, so if I change the URL with no hash, on page refresh the page would not be found. An alternate implementation would be a query string, which will properly update history when used in the pushstate, but ends up being bad UX because if the user closes the modal not using the backwards navigation (i.e. hitting the cancel button or clicking off), removing the query string would result in a page refresh.
I have a Timeline App that creates a wall posting via the Graph API. The wall posting indicates that the posting was created by the App, which is fine. However, the link for the app points to the Canvas page: http://apps.facebook.com/app_name_space.
I need the link to point to the timeline version of the App: http://www.facebook.com/pages/PAGENAME/PAGEID?sk=app_APPID
I have tried the "actions" parameter on the Post call, but that didn't solve the problem.
Redirecting the Canvas page
Since you cannot use a 301 redirect for this purpose, here is what I did (asp.net):
1) Create a folder named 'canvas' under the website root.
2) Add a default.aspx file to the folder (can't use a static file as an app landing page)
3) Add the following javascript to the head tag:
<script type="text/javascript">
var parentPageName = '<%=ConfigurationSettings.AppSettings["ParentPageName"]%>';
var appID = '<%=ConfigurationSettings.AppSettings["AppID"]%>';
var myHREF = "http://www.facebook.com/" + parentPageName + "?sk=app_" + appID;
top.location.href = myHREF;
</script>
4) Change your App Canvas url to point to the 'canvas' folder.
That's how it works, the 'via' link goes to your app, not to an arbitrary page the app is installed on, because it could be installed on any Facebook page.
Redirect users that land on the canvas app to the page tab, if that's what you want
I'm building a website where the users to essentially "mark" things from another site -- e.g. they browse a third party's catalog, and once they hit an item they like, they somehow indicate to my site about that specific item (e.g. via the url). My initial thought was to have an iframe, a "mark" button on my own site in a little bar at the top, and the third party site in the iframe -- however, I found that it's impossible to get the url of an iframe if the user navigates away from the inital url. Is there any alternative to doing this?
You can retrieve html from another site, modify it and show to your user. Sure, you should have a grant from site owner and update your modifier for any html layout update. And you will need to resolve somehow all links from the page, including css, js and so on.
Iframe is not an option, you can't control the page in a frame in any way. That's security policy for all browsers.
(I know I'm a bit late but may be someone find it useful)
I had the same problem. I came to conclusion that only way to do that is creating proxy in PHP. And that's what I did (contents of "proxy.php" file):
<?php
$proxy = 'http://yoursite.com/proxy.php';
$host = parse_url($_GET['url'], PHP_URL_HOST);
$dir = $_SERVER[DOCUMENT_ROOT].'/cache_proxy/'.$host;
if(!is_dir($dir))
mkdir($dir);
$filepath = $dir.'/'.md5($_GET['url']);
if(is_file($filepath)){
include($filepath);
}else{
$page = file_get_contents($_GET['url']);
$page = preg_replace('/(a href)=[\'\"](http.*)[\'\"]/', '$1="'.$proxy.'?url=$2"', $page);
$page = preg_replace('/(a href)=[\'"][^http](.*)[\'"]/', '$1="'.$proxy.'?url=http://'.$host.'/$2"', $page);
$page = preg_replace('/(href|src)=[\'"][^http+](.*)[\'"]/', '$1="http://'.$host.'/$2"', $page);
file_put_contents($filepath, $page);
echo $page;
}?>
Now you can insert iframe with src="http://yoursite.com/proxy.html?url=http://othersite.com"
How can I get the like count (new fans) of my Facebook fan page from a specific tab (application)?
Let us say my Facebook fan page has three tabs (hence three applications). How can I know how many likes was originated from each of these three tabs?
You will have to count them yourself as the "like" action is being performed for the same object (page object).
Use this method and the JavaScript SDK to detect when a user "likes" the page.
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
}
);
Taken from here : https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/
Once you detect the "like" you can post to your server and include the app_id. Store this in your database and hey-presto - per tab like counts :P