specify SFSafariViewController user agent - javascript

I have an issue specifying access from SFSafariViewController since it has the exact same user agent as Safari browser.
What i'm trying to do is display a picture only inside the webview and remove it if its viewed on normal browser.
Tried to see if document.refferer can be used and I tried it on twitter since the latest update has its webview changed to SFSafariViewController. Almost worked but the referrer info is also being passed to safari if its opened directly from SFSafariViewController.
Would really appreciate any ideas... thanks!!

I did a bit of quick research on this, and it appears that this is not possible, hence the word Safari in SFSafariViewController.
However you can do this using the WebKit WKWebView: https://developer.apple.com/documentation/webkit/wkwebview/1414950-customuseragent

You can't check the user agent, but there are other detection mechanisms to differentiate sfsafariviewcontroller from safari.
For example, you can check for the existence of an obscure webfont: .Helvetica LT MM.
Here's some example code: https://gist.github.com/aeharding/08eaafbb7742f78ede9b8d2f5d096354

Related

Is it possible to open a new URL in Safari from Chrome if the page is being viewed on an iOS device?

Let’s say I have a webpage and it has a button with an HREF attribute. I want the HREF of that button to be opened on Safari browser if the button is being clicked from an iOS device, even if the user is accessing the page on Google Chrome.
As of now, I only need to handle this situation for Chrome and not any generic browser. The way I see it, there are two parts to the problem:
Identifying the OS of the Client Machine: This I might be able to do easily.
Opening the Popup on Safari from Chrome: This is the tricky part I am not sure if it is possible.
I am looking for possibilities of accomplishing the second part.
Short Answer: no.
Long Answer: Some iOS apps have defined URL schemes that can be used to access the app directly from the browser. For example, twitter://timeline. But Safari for iOS does not have one.
You can detect the OS the user is using and if it Chrome then suggest the user to open it in Safari and also provide the link where to download it from. Or you can also suggest the user to make safari their default browser. ( Also provide a link on how to do that to them).

Opening browser's home page in other than IIE

I'm writing a bit of code to display an EU Cookie notification.
If the visitor does not accept the use of cookies, I want to take them somewhere else. My first thought was to take them to the browser's home page.
I found a way to do it in IE - I have been told that the method on that page is for IE 10 or less.
I have not found a way to do so in other browsers.
If this turns out to be more trouble than it is worth, I'll take them somewhere via a specific URL, such as www.google.com
Does anyone know of the method to accomplish the same thing in browsers such as Firefox, Safari, Chrome, etc?
Most browsers implement an address that will point to the home page. You should be able to redirect the user to the proper location after you figure out their browser.
For Chrome you can link them to about:newtab, which may be different from the home page, but it is probably the closest you will find. The actual homepage button is not implemented in Javascript and does not use a URL.
For Firefox you can link to about:home.
For Opera you can link to opera:speeddial. (I did not test this one, if someone wants to I'll update)
The documentation you linked to claims to be obsolete after IE10. I think you can link to about:home on IE same as Firefox if your solution isn't working afer IE10. (I did not test this one, if someone wants to I'll update).

JavaScript detect iOS Firefox

This is a follow up from Append within Append, Iframe within Append in Jquery
I realize the code works against most browsers but doesn't work in Firefox mobile iOS. Can anyone enlighten me how I can detect iOS Firefox so that I can display a error to user?
I read about modernizr about feature detect but it doesn't seems to detect about Firefox not writing to iframe if refreshed. So I wish to just display an error for now.
To detect Firefox in iOS, i only complished that after seeing user agent of Chrome, Safari and Firefox. We can see 'FxiOS' is the only difference between them, Firefox user agent string reference
. All CSS hacks dont't for iOS.
My solution:
function isFirefox() {
return navigator.userAgent.match("FxiOS");
}
You can read the user-agent with JS by using the window.navigator.userAgent property.
See: https://developer.mozilla.org/nl/docs/Web/API/NavigatorID.userAgent
For the Firefox specific values see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Gecko_user_agent_string_reference)
It would still be recommended to do feature-checking instead of checking the user-agent string, since there might be another browser out there in which it doesn't work.
If you cannot figure out which specific feature to check for to distinguish your case, you could always check for success after trying to write to the iFrame. So simple write some random data to the iFrame, try to read it back, and if you cannot read it back you display your error message. This should work for browsers you might have never even heard of.

Object Focus problem with Safari and Chrome browsers

I have the following javascript being called to request a focus when page is loaded.
This code works 100% OK with Firefox and IE7, but Chrome and Safari do not seem to move the focus at all. How to make it work with all browsers?
document.getElementById("MyFlashFile").focus();
It took me hours searching the Internet, but finally I found a solution that works on the lastest versions of IE, Firefox, Chrome and Safari.
The following code solves the problem for good:
<head>
<script type="text/javascript" src="swfobject.js"></script>
<script>
function setFocusOnFlash() {
var f=swfobject.getObjectById('myFlashObjectId');
if (f) { f.tabIndex = 0; f.focus(); }
}
</script>
</head>
<body onload="setFocusOnFlash()">
This example assumes the flash is embedded using the SWFObject library. If not, you should set the f variable to the Object or Embed tag which holds the flash movie.
Edited on 5 May 2012: Well, unfortunately it seems that the tabIndex workaround no longer works for all combinations of browser (Chrome/Safari) and operating system.
For instance, currently Chrome 18 on Windows fails.
See the link below, provided by Christian Junk, to get the status of the problem's resolution.
Unfortunately there is no way to ensure that you can set focus to a flash file that works in all browsers. IE and Firefox have solved this problem (for the most part), but Chrome and Safari are both based off of Webkit which does not have a solution.
If you ever notice on YouTube or other video / flash site that the first thing you see is something to entice you to click on the player, that is due to this problem.
One developer came up with a clever workaround, but it does involve adding some ActionScript to your flash file, this can be a pain in the ass if you are building a generic player.
Gary Bishop: Fixing Firefox Flash Foolishness
Another sort of solution is to set your wmode to opaque. I've heard this works in some situations, but will screw up cursors in text areas. I haven't had much luck with this either, but you can give it a shot.
You can find more information about the no focus bug on bugzilla.
It seems that there is a bug in Chrome:
"window.document.getElementById('swfID').focus() not working for flash objects"
http://code.google.com/p/chromium/issues/detail?id=27868
I've tried to find a workaround but I was not able to find one ;(
Regards,
Christian
In addition to Cláudio Silva answer , you need to set wmode="opaque"
Ensure this code is being called after the entire page has been rendered. It's probably being called above the HTML it refers to, so the element will not exist yet.
Various JavaScript frameworks have utilities to tell you when the DOM is ready.

Set default home page in JavaScript

How do I create a link to set the user's home page to my URL?
As some people have already answered, it used to be possible in internet explorer (prior to IE 7 I believe, could be wrong though) using something similar to
document.setHomePage('www.example.com');
I don't think any browser supports it anymore though. However, I would definitely try to convince you to do otherwise. Most people won't like having their settings automatically changed, even if it's triggered by a mouse click or other action. It's also quite likely that overzealous 'protection' programs will jump all over it and stamp it as a malicious attack.
As far as I know it's just possible in Internet Explorer
Make my Page your
<a href="javascript:history.go(0)" onClick="this.style.behavior='url(#default#homepage)';
this.setHomePage('http://www.test.de');">Startpage</a>.
I assume you mean put a link in your page to make it the browser homepage? In IE you can do something like:
this.setHomePage('http://www.mysite.com');
I don't think that works in Firefox though.

Categories