If statement not working for Safari on iPad - javascript

Here is the code, which is working fine on desktop browsers, but for some reason is breaking when I use it on Safari on my iPad.
var url = window.location.href;
if(url.indexOf("playground") != -1)
{
toggleDisplay(0);
alert("pgroud");
}
The url.indexOf("playground") is returning 21, I checked on iPad, so the code should be working, but the function and the alert are not being called.

Related

iOS Safari video/camera not working on mobile device - Javascript and Html

Safari camera/video not working on a mobile device. It says error detected with the following parameters. is there any missing line to make safari browser camera/video works?
var mediaDevices = window.navigator.mediaDevices;
mediaDevices.getUserMedia = function(c) {
return new Promise(function(y, n) {
//This line is the error// (window.navigator.getUserMedia || window.navigator.mozGetUserMedia || window.navigator.webkitGetUserMedia).call(navigator, c, y, n);
});
}
I thing your host should be secure i.e https than only that will work, because safari needs the secure host for
mediaDevices.getUserMedia

how do i make this script work on ios chrome

Ok so the code below works on every browser except ios chrome and IE.
What changes can be made to make it compatible with those browsers
<script type="text/javascript">
!function(){
var campaign_link = "http://example.com/time&"; // REPLACE WITH YOUR LINK
var t;
try{
for(t=0;10>t;++t)history.pushState({},"","#");
onpopstate=function(t){t.state&&location.replace(campaign_link)}}
catch(o){}
}();
</script>
You are getting the error because of history API. Its not supported in sme browsers
All versions below Internet Explorer 9 definitely does not support history.pushState() or history.popState()
iOS has a fair few bug with the HTML5 History API.
You can try like :
window.addEventListener("popstate", function(e) {
window.location.href = location.href;
});

Detect if the user is navigating through the safari mobile browser on iphone

I am trying to detect if the user is navigating my website from safari browser on the iphone using jquery / javascript.
I am able to detect the IOS Environment using the user agent string
/iphone/i.test(navigator.userAgent.toLowerCase())
But this detects the Apple Webkit Environment i.e. it is same for all the browsers on the device. Can anyone suggest any different approach.
UPDATED:
Try this, for detecting Safari browser in an iPhone:
var isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/);
It identifies Safari 3.0+ and distinguishes it from Chrome.
JsFiddle
Since the other answer doesn't include detection of an iPhone, including that part.
var isIphone = /(iPhone)/i.test(navigator.userAgent);
var isSafari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/);
if(isIphone && isSafari){
//do something
}
If you want to detect a particular iOS version and above, say iOS 7.0 and above then you can use the below code. It detects iOS version 7-19(for upcoming versions).
var isIphone= /(iPhone)*(OS ([7-9]|1[0-9])_)/i.test(navigator.userAgent);
var isFirefox = navigator.userAgent.indexOf("FxiOS") != -1;
var isChrome = navigator.userAgent.indexOf("CriOS") != -1;
var isEdge = navigator.userAgent.indexOf("EdgiOS") != -1;
var isOpera = navigator.userAgent.indexOf("OPT") != -1;
if (!isFirefox && !isChrome && !isEdge && !isOpera){
console.log("Only display in Safari")
} else {
console.log("Only display in Firefox/Chrome/Edge/Opera")
}
Hi, this way worked for me to detect only safari in ios mobile. The value FxiOs, CriOs, etc, I get from the userAgent value.

Android firefox version 25 and beyond Can't redirect anywhere?

Custom URL redirection is not working in android firefox latest version 25 and beyond.
If the device has an Facebook app installed, goes to app Url. If not, goes to website Url.
Now it can't redirect anywhere in Android latest firefox browser.
It worked with firefox older version, but it doesn't on the latest version 25 and beyond.
Appreciate your inputs on how to resolve this???
Demo : http://jsfiddle.net/gsk/f792D/
if (Android)
{
// this is a mobile app url
window.location.href = "fb://";
var startTime = new Date();
setTimeout(function ()
{
// Wait for 500msec
if (new Date() - startTime < 700)
{
// If we are unable to re-direct to mobile application go to website instead
if (window.location.href != "http://facebook.com")
{
window.location.href = "http://facebook.com";
}
}
else
{
goBack();
}
}, 500);
your code works fine in firefox 28 in my android mobile. it opens my fb app.
please reinstall firefox and check again.

Cross Browser Flash Detection in Javascript - chrome on Android

I've tried out the solutions proposed here:
Cross Browser Flash Detection in Javascript
but they do not seem to work in Chrome v29.0.1547 on Android v4.1.2
I'm using the code in Drupal, hence I had to escape the ' , but I do not think there is an issue with that, however here is the complete code that I've tried:
$onloadjssndsetup3 = 'jQuery(document).ready(function($){
var isFlashExists = swfobject.getFlashPlayerVersion().major !== 0 ? true : false ;
if (isFlashExists == false) {
$("#main").before("aa");};
});
';
drupal_add_js($onloadjssndsetup3, 'inline');
This code adds the "aa" to the page.
I've also tried this other code:
$onloadjssndsetup3 = 'jQuery(document).ready(function($){
var isFlashExists = swfobject.hasFlashPlayerVersion(\'1\') ? true : false ;
if (isFlashExists) {
$("#main").before("aa");};
});
';
drupal_add_js($onloadjssndsetup3, 'inline');
but it doesn't work either, the "aa" is not added in this case.
the funny part is that it's an Samsung Galaxy SIII the smart phone that I'm trying on, and flash is working on it with no prolem, it's just that I can't make the swfobject report it properly, it reports that flash is not installed.
Am I doing something wrong?
On Win8 on IE , FF it detects it properly.
Most probably there is no solution to this issue, people answered on the previous thread, but obviously it doesn't work on all versions of Android, or maybe it's just the Android version v4.1.2 that is a bit wired...

Categories

Resources