How can I redirect viewers who are blocked from social networking to an alternative page - redirect

I've looked at this Check if Facebook is blocked then redirect to try and help me solve this problem.
I have a web page that has an iframe in that contains my tumblr page. What I want is if someone is at work and social networking is blocked it won't try and load the tumblr in the src of the iframe but load my own page tumblr.htm instead.
so I got this far and realise I don't know what I'm doing really.
function isSiteOnline(url,callback) {
// try to load favicon
var timer = setTimeout(function(){
// timeout after 5 seconds
callback(false);
},5000)
var img = document.createElement("img");
img.onload = function() {
clearTimeout(timer);
callback(true);
}
img.onerror = function() {
clearTimeout(timer);
callback(false);
}
img.src = url+"/favicon.ico";
}
isSiteOnline("http://www.tumblr.com",function(found){
if(found) {
// site is online
window.location.href = 'http://my_page.tumblr.com/';
}
else {
// site is offline (or favicon not found, or server is too slow)
window.location.href = 'tumblr.htm';
}
}
Would this work and what would I put in the src of the iframe tag? would it be src="isSiteOnline" ? and that's where the problem is there are several others on one page (twitter etc.) so I'm fighting a losing battle through lack of experience. Can anyone help?

Related

Why this link's test doesn't work?

I write a test for a link with Protractor(using Pattern Page Object), but it always gave an error. So I decide to see what was going on and I write this one:
test.spec.js
it('It should redirect to Google.de', function(){
var logo = angularPage.logo3;
angularPage.clickLink(logo);
browser.getCurrentUrl().then(function (url) {
console.log('---> url:'+url);
});
});
login.page.js
this.navigate = function(ptor) {
browser.get(browser.baseUrl);
ptor = protractor.getInstance();
ptor.waitForAngular();
}
this.clickLink = function(link){
link.click();
var ptor;
this.navigate(ptor);
}
And what I got was the link didn't redirect me to another web page. I think is weird because the link actually works when I click on it. Anyone know what that can be happening?
Thanks.
My problem was that when you try to get current URL you can get it with two ways:
Supports AngularJS
var logo = angularPage.logoH3;
angularPage.clickLink(logo);
browser.getCurrentUrl().then(function (url) {
console.log('---> URL: '+url);
});
No Supports AngularJS
var logo = angularPage.logoH3;
angularPage.clickLink(logo);
browser.driver.getCurrentUrl().then(function (url) {
console.log('---> URL: '+url);
});
So login.page.js stays finally like this
login.page.js
this.clickLink = function(link){
link.click();
}
Thanks for your helping and your time ;)

Is it possible to redirect the user to Firefox browser

My current code pops up a warning box window telling the user that he or she is using IE. But is there a way to direct them to Firefox website?
public static boolean isIEBrowser()
{
return (Window.Navigator.getUserAgent().toUpperCase().indexOf("TRIDENT") != -1);
}
if (isIEBrowser())
{
SC.warn("It looks like you're using a version of Internet Explorer." +
" For the best GUI experience, please update your browser.");
}
Sure!
This might be more of what you're looking for.
String site = "http://www.mozilla.org/en-US/firefox/new/";
Window.Location.assign(site);
Window.Location.reload();
You can also add a simple timer that redirects them after a certain number of seconds or a button that takes them directly to the site.
edit:
Or... you can do this in pure javascript
JS:
function changeURL(site) {
window.location.href = site;
}
HTML:
<script>
changeURL('http://www.mozilla.org/en-US/firefox/new/');
</script>

Sharethis & Addthis

Has anyone figured out how to only increment share counts if the sharing action is completed?
They seem to count clicks.. not completed shares. That isn't a stat that is profoundly meaningful to me.
You can set it so the count displays the 'native' count:
<script type="text/javascript">stLight.options({
publisher:"Your publisher key", nativeCount:true
});</script>
However this only seems to work for Facebook, LinkedIn and a few others. For Twitter, I just replace the ShareThis count with the actual count obtained from the Twitter API, once ShareThis has loaded and the ShareThis markup exists on the page:
var pageUrl = 'http://www.google.com/';
updateTwitter();
function updateTwitter() {
if (jQuery('.st_twitter_vcount .stBubble_count').length > 0) {
jQuery.getJSON('http://urls.api.twitter.com/1/urls/count.json?url=' + pageUrl + '&callback=?',
function(data) {
jQuery(".st_twitter_vcount .stBubble_count").html(data.count);
});
}
else {
setTimeout(function() {
updateTwitter();
}, 50);
}
}
Just change the pageURL variable to the URL you want to display statistics for.
Hope that helps,
Kamal.
Ended up rolling my own. Neither seems to support this.

Redirect from app page to fan page

Hei.
Is there any other way to redirect users from app page (apps.facebook.com) to the fan pages app site (/pages/example/appid=123456789).
I actually doing it with this code:
<script type="text/javascript">
function NotInFacebookFrame() {
return top === self;
}
function ReferrerIsFacebookApp() {
if(document.referrer) {
return document.referrer.indexOf("apps.facebook.com") != -1;
}
return false;
}
if (NotInFacebookFrame() || ReferrerIsFacebookApp()) {
top.location.replace("http://fanpage.com");
}
</script>
Because if you get an invite you get sent to the app page, not to the fan page.
But the redirection is slow, and i saw some apps where the redirection is very fast.
Here is the app where it redirects like i want: http://www.facebook.com/apps/application.php?id=402068793183793
HOW do i get this redirection message? i can't find any solution....
Best regarts, Andreas.

How can i redirect all http to https facebook pages?

I want to force all parent windows of my application from this url:
http://apps.facebook.com/app_name/
to this:
https://apps.facebook.com/app_name/
(http to https)
How can i do this?
Thanks!
You can use something like this (be warned that this will leave your application without signed_request):
if (document.location.protocol=='http:'){
document.location.protocol = 'https:';
}
If you do want the parent frame (Facebook itself) to be switched to HTTPS as well than you'll need to know the URL of your page within application:
if (document.location.protocol=='http:'){
window.top.location = 'https://YOUR_APPLICATION_PAGE_URL'
}
You probably know the URL pattern for your application and do know the Canvas URL of it, so something like this may fit:
if (document.location.protocol=='http:'){
var applicationUrl = 'https://facebook.com/example-application';
var canvasURL = 'http://example.com/facebook-canvas';
var currentAppPageUrl = (document.location+'').replace(canvasURL, applicationUrl);
window.top.location = currentAppPageUrl;
}
Canvas app is at your domain and top is at Facebook domain, so calling window.top.location inside Facebook Canvas app causes cross domain URL access from iframe.
All you need is to catch the exception via try catch block.
if (document.location.protocol=='http:'){
var applicationUrl = 'https://facebook.com/example-application';
var canvasURL = location.protocol+'//'+location.host+location.pathname;
var currentAppPageUrl = (document.location+'').replace(canvasURL, applicationUrl);
try {
window.top.location = currentAppPageUrl;
} catch (e) {
}
}