This question already has answers here:
Detect if user is using webview for android/iOS or a regular browser
(15 answers)
detect ipad/iphone webview via javascript
(16 answers)
Closed 8 days ago.
How can I detect if user is accessing my website in Webview or on browser?
My websites backend is PHP and Frontend is Vue.
I have found this function in this site: https://codepen.io/jackmu95/pen/NLzqJR
It worked well for me.
function isWebview() {
const navigator = window.navigator
const userAgent = navigator.userAgent
const normalizedUserAgent = userAgent.toLowerCase()
const standalone = navigator.standalone
const isIos =
/ip(ad|hone|od)/.test(normalizedUserAgent) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1)
const isAndroid = /android/.test(normalizedUserAgent)
const isSafari = /safari/.test(normalizedUserAgent)
const isWebview = (isAndroid && /; wv\)/.test(normalizedUserAgent)) || (isIos && !standalone && !isSafari)
return isWebview
}
Related
This question already has answers here:
Extract URL from string
(5 answers)
Extracting for URL from string using regex
(3 answers)
Closed 1 year ago.
I have a linkify url text which is in chat message which O needs to allow even <x x> after a valid url. Now when I am using any string after url, it ends up with
InvalidCharacterError: Failed to execute 'createElement' on
'Document': The tag name provided ('x<') is not a valid name.
This should allow
before & after strings Ex: Hi this is test page https://www.test.com as well
Code
sendUrlText(e) {
if (e && e.keyCode && e.keyCode !== 13) return;
var stateMessage = unescape(this.state.message);
function linkify(stateMessage){
return stateMessage.replace(/(https?:\/\/[^\s]+)/g, "<a href='$1' target='_blank'>$1</a>")
}
var formattedMessage = linkify(stateMessage);
}
Any suggestion how can I allow /< x x > after url and turns it into
For example:
with a linkify url.
You mean like this?
function linkify(stateMessage) {
const string = stateMessage.match(/(https?:\/\/[^ ]*)/);
if (!string) return ""
const url = new URL(string[1])
return stateMessage.replace(string[1],`<a href='${url.toString()}' target='_blank'>${url.toString()}</a>`)
}
const link = linkify('Hello, this is a link https://www.test.com/ with a space and valid text')
console.log(link)
document.getElementById("urlOutput").innerHTML = link;
<span id="urlOutput"></span>
I'm aware it's a duplicate, but I tried the following:
How to detect the stock Android browser
var navU = navigator.userAgent;
// Android Mobile
var isAndroidMobile = navU.indexOf('Android') > -1 && navU.indexOf('Mozilla/5.0') > -1 && navU.indexOf('AppleWebKit') > -1;
// Apple webkit
var regExAppleWebKit = new RegExp(/AppleWebKit\/([\d.]+)/);
var resultAppleWebKitRegEx = regExAppleWebKit.exec(navU);
var appleWebKitVersion = (resultAppleWebKitRegEx === null ? null : parseFloat(regExAppleWebKit.exec(navU)[1]));
// Chrome
var regExChrome = new RegExp(/Chrome\/([\d.]+)/);
var resultChromeRegEx = regEhttps://www.quora.com/What-is-samsung-s5s-native-browser-Is-it-different-for-different-android-flavorsxChrome.exec(navU);
var chromeVersion = (resultChromeRegEx === null ? null : parseFloat(regExChrome.exec(navU)[1]));
// Native Android Browser
var isAndroidBrowser = isAndroidMobile && (appleWebKitVersion !== null && appleWebKitVersion < 537) || (chromeVersion !== null && chromeVersion < 37);
This doesn't work for above mentioned devices. I get false on Galaxy S5 / S6 native browser.
I also tried (Javascript detect android native browser):
var nua = navigator.userAgent;
var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));
This works, but also returns true for Chrome.
I'd like to improve on second piece of code so it returns true only for native browser, not chrome.
According to https://www.quora.com/What-is-samsung-s5s-native-browser-Is-it-different-for-different-android-flavors, S5 and S6 use a browser called "Internet". Is there a way to improve above snippet so it handles this browser as well?
There are lots of "Chromia" out there (as PPK shared here, mentioning HTC's and LG's as well as our Samsung Internet). Samsung Internet isn't the old "stock", a.k.a AOSP, Android browser, but our own Chromium-based browser.
I'm not sure what your intention is in trying to determine if it's Samsung Internet rather than Chrome (Perhaps analytics? Hopefully not for bug fixes?) but you may find this guide to our user agent strings here helpful:
http://developer.samsung.com/internet/user-agent-string-format
This question already has answers here:
How to find out what character key is pressed?
(10 answers)
Closed 7 years ago.
so I need to show what key is being pressed in my web app , I want to put it in html 5 canvas.
when I'm pressing Q , it will show the Q button.
Here my code(i'm using javascript):
window.addEventListener("keypress",onKeyPress);
function onKeyPress(e)
{
console.log(e.keyCode);
var str = String.fromCharCode(e.keyCode);
console.log(str+":"+e.keyCode);
var tune = new Audio();
if (e.keyCode == 113)
{
tune = new Audio("Assets/Tune/C.mp3");
tune.play();
}
}
can anyone tell me what function do I need to show the key ?
If there's already solution, please give me the link, I've tried to search before but can't find anything.
Thanks
You have a problem...
The key code changes in different operation systems.
Here you get a table with some key codes:
http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
You can show each key pressed with something like this I guess:
var str = String.fromCharCode(e.keyCode);
var c = document.getElementById("Canvas");
var ctx = c.getContext("2d");
ctx.font = "30px Arial";
ctx.fillText(str,10,50);
You're almost there.
I have made a slight tweak to your javascript below:
window.addEventListener("keypress",onKeyPress);
function onKeyPress(e) {
var keyPressed = e.which || e.keyCode;
console.log(keyPressed);
var str = String.fromCharCode(keyPressed);
console.log(str+":"+keyPressed);
var tune = new Audio();
if (e.keyCode == 113)
{
tune = new Audio("Assets/Tune/C.mp3");
tune.play();
}
}
This question already has answers here:
How do I check if an array includes a value in JavaScript?
(60 answers)
Closed 8 years ago.
var position = prompt("position:");
var manager = ["John", "Alex", "Joe"];
var admin = ["Texas", "Jesus", "Rick"];
var tech = ["Nexus", "Thomas", "Fred"]
if (position == manager) {
alert("manager")}
if (position == admin) {
alert("admin")}
if (position == tech) {
alert("tech")
}
else {
alert("Incorrect position")
}
I would like to ask how it is possible to this program work. When I will enter in prompt John I would like to get alert manager when I will enter in prompt Rick I would like to have alert tech etc...
And also if I will enter something what is unknown random value it will get me Incorrect position.
Also I would like to ask if there is way when I will enter in prompt for example jOHN or john it will work. I am total beginner in JS and coding.
You can use indexOf, for example:
if (manager.indexOf(position) !== -1) {
alert("manager");
}
Use .indexOf()
if (manager.indexOf(position) != -1) {
alert("manager")
}
I use FlashDevelop (great and free alternative to Flash Builder) that uses the (latest) open source Flex framework of Adobe.
I want to develop an app for Android and iOS as well. In some parts I use an StageWebView to display content that i don't want to rewrite to flex AS3 code.
In a nutshell: I am in an early stage of development and this is my first flex mobile app. In some parts it uses the HTML5 feature 'localStore' (part of object window in javascript) to store some data. But it seems that this feature is not available in the webkit browser of flex? I also want to know if this is a typical flex problem or does it also exists when the app will be deployed? The problem does not occur when loading the HTML part on a mobile device (for example in mobile safari).
Also when the localStorage feature is not available it will switch back to cookies. But this is also not working correctly. In all other browsers no problemo, even in IE.
Result of cookie: varname=undefined; expires=Thu, 03 May 2012 01:01:41 GMT.
What is going on?
Here is some Javascript code:
// Picked up from: https://github.com/carhartl/jquery-cookie
// Usage: http://www.electrictoolbox.com/jquery-cookies/
jQuery.cookie = function (key, value, options) {
// key and at least value given, set cookie...
if (arguments.length > 1 && String(value) !== "[object Object]") {
options = jQuery.extend({}, options);
if (value === null || value === undefined) {
options.expires = -1;
}
if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
value = String(value);
return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}
// key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
Local storage:
jQuery.locstore = function(key, val, opt ) {
var ls = window.localStorage,
j = window.JSON,
b = !( !ls || !j );
if( !b )
{ return jQuery.cookie( key, val, opt ); }
// set
if( arguments.length > 1 )
{
var bRem = (val == null ),
v = (bRem || typeof val == 'number' || typeof val == 'string')?val:j.stringify(val);
if( bRem )
{ b = ls.removeItem(key); }
else { b = ls.setItem(key, v); }
return b;
}
// get
var v = ls.getItem(key);
if( v != null && typeof val != 'number' )
try { v=j.parse(v); } catch(e){}
return v;
};
I ask it here because i didn't find an answer on the net. Maybe someone give me a clue into the right direction to solve this?
But it seems that this feature is not available in the webkit browser
of flex
There is no webkit browser in the Flex Framework.
A version of Webkit is included in Desktop AIR runtime; but that won't matter for mobile applications.
Mobile AIR uses the underlining browser engine of the OS (Android or iOS) for StageWebView. I'm not sure of specifics; nor what functionality is exposed via the "Browser in the app" but here is a quote from the docs to confirm this:
On devices in the mobile and extended mobile profiles, the
StageWebView class uses the system web control provided by the device
operating system. Thus, the available features and rendering
appearance may vary from device to device.
So, I surmise that your issue has nothing to do with Flex, nor AIR, but rather the support of the browser in the OS you're testing on.
These may be of help to you:
http://helpx.adobe.com/air/kb/stagewebview-differences-platforms-air-sdk.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/StageWebView.html
http://xperiments.es/blog/en/stagewebviewbridge-comunicacion-entre-actionscript-y-javascript-y-viceversa/
http://coenraets.org/blog/2011/07/using-jquery-in-a-flex-application/
(View the previous post also. The link is in the first paragraph.)
Hope one of the last two can help solve the problem / give you a work-around.
Todd
Apparently Air's stageWebView doesn't support localStorage. Even though it isn't a perfect solution, after spending months looking for a solution, I replaced localStorage with sessionStorage, and was able to load my file correctly.
Take in mind, sessionStorage only works with the loadURL method of stageWebView, loadString doesn't have localStorage nor sessionStorage.
Edit: sessionStorage appears to be working only in android. I can't get neither: localStorage nor sessionStorage to work in Adobe Air for iOs.
Edit 2: Apparently February update of Adobe Air allows localStorage on Android's Adobe Air. (haven't tested it yet)