How to redirect to mobile site for specific range of android versions - redirect

I would like to redirect site to mobile version only for android versions below a certain build, specifically below Ice Cream Sandwich, that is API level 14
I am able to at present only redirect for a certain build and unable to redirect for a range of builds. Please suggest how to redirect for a range of builds.
This is the code which I am using -
<script type="text/javascript"> // <![CDATA[
if ( (navigator.userAgent.indexOf('Android 4.2.2') != -1) ) {
document.location = "http://www.yoururladdress.com/yourpage.html";
} // ]]>
</script>

Found answer to this question.
Code is as follows -
<script>
<!--
var str = navigator.userAgent ;
var version = str.match(/Android\s+([\d\.]+)/)[1];
var version = version.substring(0, 3);
if(version <= 4.0)
location.replace("http://www.yoururladdress.com/yourpage.html");
}
-->
</script>

Related

How to stream video to browser with Kodi

Not sure if this is the correct place to ask this but here goes nothing.
I setup openelec's Kodi on a Raspberry pi2. I uploaded a video and managed to get it to play on a connected TV via HDMI. What I can't seem to figure out is how to have Kodi serve as a media server so I can browse media using my phone's or computer's browser and play it. I've been through the settings available, installed several addons(i.e chorus etc) and I still can't see how to make this happen. Whenever I open a video on my browser after logging into the Kodi web interface, it still plays it on the TV connected to the PI.
Almost all Google results out there talk about casting from device onto TV and chromecast. I want to be able to play this media on my local browser. And no, I can't use the Kodi app because I'm using an un-supported Phone and computer OS.
In your case, it's better to use plex instead of kodi.
Kodi is not exactly a media server, it works as a media center. However, with plex, you can set up your media center and have access to your media from your web browser.
Try looking for the differences between kodi and plex.
Chorus should still have an option to play the video in the browser. It seems to not work with Chrome or Firefox anymore, but have a look here: https://github.com/xbmc/chorus2/issues/127
This functionality depends on Flash Player, this feature had been removed from most of the web-browsers.
REF: https://support.google.com/chrome/answer/6258784?visit_id=637521928282450874-904852602&rd=1
I've modified the Chorus web interface to allow streaming with a nodejs process in the background.
NodeJS script:
const express = require('express')
const fs = require('fs')
const path = require('path')
const app = express()
const url = require('url')
const gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(fs)
app.get('/video', function(req, res) {
var q = url.parse(req.url, true).query;
var filepath = q.src;
fs.stat(filepath, function(err, stats){
if (err){
if (err.code === 'ENOENT'){
//404 Error if file not found
res.writeHead(404, {
"Accept-Ranges" : "bytes",
"Content-Range" : "bytes " + start + "-" + end + "/" + total,
"Content-Length" : chunksize,
"Content-Type" : "video/mp4"
});
}
res.end(err);
}
var start;
var end;
var chunksize;
var total = stats.size;
var range = req.headers.range;
if (range) {
var parts = range.replace(/bytes=/, "").split("-");
start = parseInt(parts[0], 10);
end = parts[1] ? parseInt(parts[1], 10) : total - 1;
} else {
start = 0;
end = total - 1;
}
if (start > end || start < 0 || end > total - 1){
//error 416 is "Range Not Satisfiable"
res.writeHead(416, {
"Accept-Ranges" : "bytes",
"Content-Range" : "*/" + stats.size,
"Content-Type" : "video/mp4"
});
res.end();
return;
}
if (start == 0 && end == (total -1)){
res.writeHead(200, {
'Accept-Ranges': 'bytes',
'Content-Range': `bytes ${start}-${end}/${total}`,
'Content-Length': total,
'Content-Type': 'video/mp4'
});
} else {
chunksize = (end - start) + 1;
res.writeHead(206, {
'Content-Range': `bytes ${start}-${end}/${total}`,
'Accept-Ranges': 'bytes',
'Content-Length': chunksize,
'Content-Type': 'video/mp4'
});
}
var stream = fs.createReadStream(filepath, {
start : start,
end : end
}).on("open", function() {
stream.pipe(res);
}).on("error", function(err) {
console.log(err);
res.end(err);
});
});
});
app.listen(<port>, function () {
console.log('Listening on port <port>!');
});
Modified the file "Kodi\addons\webinterface.chorus\tpl\MovieView.html" under div id="movie-watch" so:
<div id="movie-watch" class="tab-pane">
<div class="col-1">
<video id="videoPlayer" controls width="100%" height="90%" preload="metadata">
<source src="http://<mydomain>:<port>/video?src=<%=encodeURIComponent(file) %>&movieId=<%= movieid %>" type="video/mp4">
</video>
<!--
<h2>HTML5 player</h2>
<p>Codec support is very limited in the browser.
H.264 video generally works but only with 2 channel audio. Works best in Chrome, may crash browser and/or XBMC!</p>
<div class="buttons">
Launch HTML5 player
</div>
<br />
<h2>VLC player</h2>
<p>VLC Player provides an
embeddable video player, it will play most videos, but does require you to
download and install extra software.
Works well in Chrome and Firefox.</p>
<div class="buttons">
Launch VLC player
</div>-->
Modified the file "Kodi\addons\webinterface.chorus\tpl\TvshowView.html" under div id="movie-watch" so:
<div id="tv-watch" class="tab-pane">
<div class="col-1">
<video id="videoPlayer" controls width="100%" height="90%">
<source src="http://<mydomain>:<port>/video?src=<%=encodeURIComponent(file) %>&episodeId=<%= episodeid %>" type="video/mp4">
</video>
<!--
<h2>HTML5 player</h2>
<p>Codec support is very limited in the browser.
H.264 video generally works but only with 2 channel audio. Works best in Chrome, may crash browser and/or XBMC!</p>
<div class="buttons">
Launch HTML5 player
</div>
<br />
<h2>VLC player</h2>
<p>VLC Player provides an
embeddable video player, it will play most videos, but does require you to
download and install extra software.
Works well in Chrome and Firefox.</p>
<div class="buttons">
Launch VLC player
</div>-->

Include Google Analytics to TYPO3

I've added the javascript for Google Analytics by using TYPO-Script (in Template):
page.headerData.124034 = TEXT
page.headerData.124034.value (
<!-- Google Analytics -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push (['_setAccount', 'UA-##-my-ID-##']);
_gaq.push (['_gat._anonymizeIp']);
_gaq.push (['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- Google Analytics End -->
)
TYPO3 renders on frontend:
<!-- Google Analytics -->
<!-- Google Analytics End -->
So the complete script-section is missing. My code worked on TYPO6 6.1.3 very well. I think it stopped working when i updated to TYPO3 Version 6.1.4 or 6.1.5.
Has anyone a idea how get it to work again?
Maybe the TEXT-Type do not accept script tags anymore.
Try to use:
page.includeFooterJS.c (
<script type=”text/javascript”>
alert(“Yes, scripts can also be added inline.”);
</script>
)
Or:
http://typo3.org/extension-manuals/footer_js/0.0.1/view/1/3/
Probably there is sth wrong with your template, e.g. some other template is overriding this value.
Have you checked if you see correct value in the Template object browser?
I have tested the exact code you have shared and it worked without an issue in TYPO3 v8.7

Errors in IE 8 from connect.facebook.net/en_US/all.js caused by credits callback

Setup:
Got a working facebook app and am correctly setup for facebook credits transactions (i.e. everything on the serverside is working fine).
In Firefox and chrome transactions complete without issue, however in IE8 the callback upon completing/closing the purchase dialog throws the following errors:
Error 1:
Line: 52 Error: Object doesn't support this property or method
Object doesn't support this property or method JScript - script block, line 52 character 37
Where the function it points to is:
ui: function( params )
{
obj = FB.JSON.parse( params );
method = obj.method;
cb = function( response ) { FBAS.getSwf().uiResponse( FB.JSON.stringify( response ), method ); }
FB.ui( obj, cb );
},
Specifically highlighting this bit:
FBAS.getSwf().uiResponse( FB.JSON.stringify( response ), method )
in the http://connect.facebook.net/en_US/all.js file
Error 2:
Line: 65 Error: Object doesn't support this action
Object doesn't support this action all.js, line 65 character 2198
[The line it points to is a stupidly long unformatted unreadable mess so I'll omit it unless requested]
Specifically highlighting this bit:
delete d._old_visibility
again in the http://connect.facebook.net/en_US/all.js file
The html I'm using (with the app identifying stuffs removed) is as follows:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Expires" content ="0" />
<meta http-equiv="Pragma" content ="no-cache" />
<meta http-equiv="Cache-Control" content ="no-cache" />
<title>[ APP NAME ]</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script type="text/javascript">
$(document).ready
(
function()
{
var appId = [ APP ID ];
var host = [ APP HOST ];
// If the user did not grant the app authorization go ahead and
// tell them that. Stop code execution.
if (0 <= window.location.href.indexOf ("error_reason"))
{
$(document.body).append ("<p>Authorization denied!</p>");
return;
}
// Loads the Facebook SDK script.
(function(d)
{
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
// When the Facebook SDK script has finished loading init the
// SDK and then get the login status of the user. The status is
// reported in the handler.
window.fbAsyncInit = function()
{
//debugger;
FB.init(
{
appId : appId,
status : true,
cookie : true,
oauth : true,
});
FB.getLoginStatus (onCheckLoginStatus);
};
// Handles the response from getting the user's login status.
// If the user is logged in and the app is authorized go ahead
// and start running the application. If they are not logged in
// then redirect to the auth dialog.
function onCheckLoginStatus (response)
{
if (response.status != "connected")
{
top.location.href = "https://www.facebook.com/dialog/oauth?client_id=" + appId + "&redirect_uri=" + encodeURIComponent (host+"[ RELATIVE APP PATH ]") + "&scope=publish_stream,user_about_me,read_friendlists,user_photos";
}
else
{
// Start the application
loadGame();
}
}
}
);
function loadGame()
{
var flashvars = {};
var params = {};
var attributes = {};
params.allowscriptaccess = "always";
attributes.id = 'flashContent';
attributes.name = 'flashContent';
swfobject.embedSWF("[ APP SWF ]?"+Math.floor(Math.random()*10000), "flashContent", "100%", "99%", "10.0", null, flashvars, params, attributes);
}
</script>
<div id="flashContent" >
Loading...
</div>
</body>
This is just a problem for IE 8 but is stopping the app going live since a significant number of users transactions would fail (or rather would complete, be charged and not take effect due to the failed callback).
For the past few days I've been searching for others with this or a similar problem but to no avail.
I've seen some similar issues where people are warned about javascript variables being created globally and causing interfereance or variables being names using keywords reserved in IE but as far as I can tell neither is the case here. The facebook javascript code is fairly boilerplate stuff lifted from facebook dev pages and reliable sources. It may be JQuery (which I have little experience with), however, again, this is lifted from working examples and if there is a problem I can't see it.
Can anyone help?
SOLVED
I won't accept this answer because I honestly don't think the question was answerable/solvable with the info provided and feel it would be bad form. But I want to leave this here for anyone that might be looking for a solution.
Cause of the error
The problem is the result of the combination of facebook hiding the app during 'normal' facebook actions (in this case, displaying the pay prompt) and external interface calls not working in Internet explorer when the app is hidden/not visible.
Solution
Found at http://flassari.is/2012/02/external-interface-error-object-expected/#comment-1743
All of these steps may not be neccessary but in the end what I did was:
Stop facebook hiding the app by overriding the visibility using
<style>
#[ ID OF THE FLASH OBJECT]
{
visibility: visible !important;
}
</style>
Adding wmode = "opaque"; to the swfobject params
Using the optional flash_hide_callback by adding hideFlashCallback:"OnHideFlash" to the FB.init options in the actionscript to move/hide the app instead, where OnHideFlash is a javascript function:
function OnHideFlash(params)
{
if (params.state == 'opened')
{
getSwf().style.top = '-10000px';
} else
{
getSwf().style.top = '';
}
}
Where getSwf() is your prefered method of getting the flash app object.
Hopefully this will save some people the suffering of pouring through the endless 'reasons that XYXY doesn't work in IE' questions and solutions that has been my last few days.
I suggest putting your code through a JavaScript Lint tool and correcting any errors you find. IE8 is extremely picky about how JavaScript is coded, while Firefox and Chrome are ok with minor mistakes. If your code is error free (after linting), it should work properly.

Is it possible to use google web fonts in gmail

I want to use google web font "Over the Rainbow" when composing mail in gmail
<link href='http://fonts.googleapis.com/css?family=Over+the+Rainbow&v2' rel='stylesheet' type='text/css'>
Is it possible?
<script type="text/javascript">
WebFontConfig = {
google: { families: [ 'Over+the+Rainbow' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})(); </script>
I wish the answer were different, but I do not believe it is currently possible.
I don't believe Gmail will allow you to insert a link element into the message body (although some email clients will).
Gmail will not allow you to run JavaScript within the message.

Why FB.getLoginStatus doesn't work in IE7?

I am using FB.getLoginStatus for an application in Facebook. This works fine in all the browsers, including IE8. But it doesn't work for IE7. My code is:
FB.getLoginStatus(function(response) {
if (response.session) {
alert("logout");
}
else{
FB.Event.subscribe('auth.login', function(response) {
login();
});
alert("login");
}
});
Does anyone know why?
According to the documentation at http://developers.facebook.com/docs/reference/javascript/fb.init/, the proper solution is to create a file on your web server (for instance channel.html) containing just:
<script src="http://connect.facebook.net/en_US/all.js"></script>
And then specifying the absolute URL to your channel.html in your init options:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'YOUR APP ID',
channelUrl : 'http://example.com/channel.html' // custom channel
});
</script>
For convenience in deployment, I use the following to calculate my channelUrl.
var curLoc = window.location;
curLoc.protocol + "//" + curLoc.hostname + ":" + curLoc.port + "/channel.html"
Currently this API (FB.getLoginStatus) is not working anymore on IE7 browsers.
Take a look here:
getLoginStatus not Fired on IE7
If you try to run the code in the following page on IE7 it's not working:
http://www.fbrell.com/auth/login-and-logout
It seems the "channelUrl" fix is not working anymore and the IE7 support for the Facebook Javascript SDK is compromised.