I have a fb application and i when i press the like button i want to refresh page or even redirect it to the same url.
I have this code:
<script type="text/javascript">
FB.Event.subscribe('edge.create',
function(response) {
window.top.location.href = "http://www.myurl.com";
}
</script>
Works perfectly in Firefox not in Chrome..
Any ideas?
Thanks in advance!
Related
When i click on a link this will redirect me to another page in my app.
But after that when i am clicking on the mobile's back button it is not redirect me to previous page.
Ca anyone have answer of this question.
Actually device's back button click is also an event in PhoneGap. You can define the beckbutton event as a function.
<html>
<head>
<title>Sample</title>
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", backButtonClick, false);
}
function backButtonClick() {
//Do something here on backbutton click or go back to last page.
window.history.back()
}
</script>
</head>
<body>
</body>
</html>
Its a sample, now tweak your page as you wanted.
Always write the backbutton event on deviceready!
This is my first stackoverflow question. yay.
Ok. I am attempting to splittest or a/b test copy for a featured facebook like button by using google analytics:
_gaq.push(['_trackEvent', 'facebook', 'click', 'amazing copy that hypnotizes user into clicking like']);
All fine and dandy so far.
To reign in the like/unlikes I found this snippet:
<script type="text/javascript">
<!--
FB.Event.subscribe('edge.create', function(href, widget) { _gaq.push(['_trackEvent', 'facebook', 'click', 'amazing copy that hypnotizes user into clicking like']); });
FB.Event.subscribe('edge.remove', function(href, widget) { _gaq.push(['_trackEvent', 'facebook', 'click', 'amazing copy that hypnotizes user into clicking like']); });
-->
</script>
Ok, everyone is with me so far? Now this (in theory) will give me like and unlikes for the featured experimental like button, but it will ALSO send data on other like buttons on the page, correct?
The question is: How do I isolate the edge.create callback (or whatever) to only fire when the desired like-button is clicked? Is there parrameters or arguments I can pass to the fb.event.subscribe that will check if the 'liked' url is the desired facebook page, maybe? or maybe if the liked url differs from the domain?
I am a total newb with js, jquery, and anything beyond basic php, html, or css. please help! :P
This is the actual documentation for FB.Event.subscribe.
I don't know where you got your snippet but the doc says it only returns 1 parameter in the callback.
FB.Event.subscribe('edge.create', function(response) {
alert('You liked the URL: ' + response);
});
If you want to separate like buttons, the answer is not in what you pass to the function, but what you receive from the callback.
After you receive the data in response, that is where you do the separate action you want with each URL to be liked. That 'data' in response is the URL that the user liked.
In that way of thinking, then you should:
FB.Event.subscribe('edge.create', function(response) {
if(response == "FULL-URL-YOU-WANT-SEPARATED"){
_gaq.push(['_trackEvent', 'facebook', 'click', 'amazing separate copy that hypnotizes user into clicking its own like button']);
}
});
If you want to detect if that URL is any link from a specific domain, you might wanna get the URL's domain and check if response startsWith it.
EDIT:
Try this and see if theres a pop-up box, only when your own like button is clicked.
FB.Event.subscribe('edge.create', function(response) {
if(response == "https://www.facebook.com/mysticpoliticsradio"){
alert("Your like button has been clicked.");
_gaq.push(['_trackEvent', 'facebook', 'click', 'amazing separate copy that hypnotizes user into clicking its own like button']);
}
});
Use it like
function(response,widget) {
if(widget.dom.id == "your fb_button_id"){
alert("Your like button has been clicked.");
_gaq.push(['_trackEvent', 'facebook', 'click', 'amazing separate copy that hypnotizes user into clicking its own like button']);
}
}
add your fb button like this
<div class="fb-like" data-send="false" data-layout="box_count" id="fb_button_id"></div>
I have this fb-login button on my website and it works pretty okay.
How can I implement an logout button? Below is my code for the login part.
<fb:login-button size="small" onlogin="RedirectLogon();" perms="email,user_birthday" autologoutlink="true">
<%=LanguageManager.Instance.Translate("root/facebook/login")%>
</fb:login-button>
If you want to implement such buttons into one multifunctional button, use this:
<fb:login-button autologoutlink="true"></fb:login-button>
Note that if you add any custom code to the above line, the button won't work.
You can do it by using the following HTML and javascript function.
<script>
function fbLogout() {
FB.logout(function (response) {
//Do what ever you want here when logged out like reloading the page
window.location.reload();
});
}
</script>
<span id="fbLogout" onclick="fbLogout()"><a class="fb_button fb_button_medium"><span class="fb_button_text">Logout</span></a></span>
I have two links on an optimized mobile Safari web site. One is a link to the App Store to download my application. The other is a Launch App button which uses the registered app:// protocol to open the application. The problem is that mobile Safari chokes when the user clicks the Launch App button if the application is not installed. Is it possible to detect if the registered protocol is available, and if it isn't, change the Launch App button with an appropriate URL, such as the download app URL, so that the user doesn't get a nasty popup?
This is broadly similar to this question; the most relevant suggestions there are to have a single button that attempts to launch the app, simultaneously creating a timer that'll fire if the app isn't installed on the grounds that if it were then Safari would have exited before the timer fires.
If you add an iframe on your web page with the src set to custom scheme for your App, iOS will automatically redirect to that location in the App. If the app is not installed, nothing will happen. This allows you to deep link into the App if it is installed, or redirect to the App Store if it is not installed.
For example, if you have the twitter app installed, and navigate to a webpage containing the following markup, you would be immediately directed to the app. If you did not have the Twitter app installed, you would see the text "The Twitter App is not installed."
<!DOCTYPE html>
<html>
<head>
<title>iOS Automatic Deep Linking</title>
</head>
<body>
<iframe src="twitter://" width="0" height="0"></iframe>
<p>The Twitter App is not installed</p>
</body>
</html>
This means that you could have a single button that directs to a web page with markup similar to this:
<!DOCTYPE html>
<html>
<head>
<title>iOS Automatic Deep Linking</title>
<script src='//code.jquery.com/jquery-1.11.2.min.js'></script>
<script src='//mobileesp.googlecode.com/svn/JavaScript/mdetect.js'></script>
<script>
(function ($, MobileEsp) {
// On document ready, redirect to the App on the App store.
$(function () {
if (typeof MobileEsp.DetectIos !== 'undefined' && MobileEsp.DetectIos()) {
// Add an iframe to twitter://, and then an iframe for the app store
// link. If the first fails to redirect to the Twitter app, the
// second will redirect to the app on the App Store. We use jQuery
// to add this after the document is fully loaded, so if the user
// comes back to the browser, they see the content they expect.
$('body').append('<iframe class="twitter-detect" src="twitter://" />')
.append('<iframe class="twitter-detect" src="itms-apps://itunes.com/apps/twitter" />');
}
});
})(jQuery, MobileEsp);
</script>
<style type="text/css">
.twitter-detect {
display: none;
}
</style>
</head>
<body>
<p>Website content.</p>
</body>
</html>
Below is a code snippet that works, but is not perfect. You still see the safari popup, but everything else works as expected:
<script type="text/javascript">
var timer;
var heartbeat;
var lastInterval;
function clearTimers() {
clearTimeout(timer);
clearTimeout(heartbeat);
}
window.addEventListener("pageshow", function(evt){
clearTimers();
}, false);
window.addEventListener("pagehide", function(evt){
clearTimers();
}, false);
function getTime() {
return (new Date()).getTime();
}
// For all other browsers except Safari (which do not support pageshow and pagehide properly)
function intervalHeartbeat() {
var now = getTime();
var diff = now - lastInterval - 200;
lastInterval = now;
if(diff > 1000) { // don't trigger on small stutters less than 1000ms
clearTimers();
}
}
function launch_app_or_alt_url(el) {
lastInterval = getTime();
heartbeat = setInterval(intervalHeartbeat, 200);
document.location = 'myapp://customurl';
timer = setTimeout(function () {
document.location = 'http://alternate.url.com';
}, 2000);
}
$(".source_url").click(function(event) {
launch_app_or_alt_url($(this));
event.preventDefault();
});
</script>
I have blogged about the details here: http://aawaara.com/post/74543339755/smallest-piece-of-code-thats-going-to-change-the-world
<script
src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
type="text/javascript"></script>
<script type="text/javascript">
FB.init('cef61789d5df166ac00c9fe13007c110', "xd_receiver.htm");
FB.Connect.showPermissionDialog("offline_access");
</script>
After a user login i am using the above code to get the Dialog box.
Why itsnt showing permission dialog??
I had this problem. Wrap the call to FB.Connect inside an "ensure init" like so:
FB.ensureInit(function() { FB.Connect.showPermissionDialog("offline_access"); });
That cleared things up for me.