简体   繁体   English

如何使用javascript检测在webview或浏览器中打开的网站

[英]how to detect website open in webview or browser using javascript

I want the JavaScript code for checking whether a website is open in webview (in application webview) or mobile Browser (like google chrome, uc browser). 我想要用于检查网站是否在webview(在应用程序webview中)或移动浏览器(例如google chrome,uc浏览器)中打开的JavaScript代码。

I referred to these links: But it's not working for me .. 我指的是这些链接:但这对我不起作用..

Detect inside Android Browser or WebView 在Android浏览器或WebView中检测

Activity -> onCreate 活动-> onCreate

this.webView.getSettings().setUserAgentString(
    this.webView.getSettings().getUserAgentString() 
    + " "
    + getString(R.string.user_agent_suffix)
);

Res -> Values -> strings.xml RES->值-> strings.xml

<string name="user_agent_suffix">AppName/1.0</string>

Javascript Java脚本

function() isNativeApp {
    return /AppName\/[0-9\.]+$/.test(navigator.userAgent);
}

copied from here 这里复制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在网站中使用 jquery/javascript 检测从 web 浏览器(chrome)或 webview(移动应用程序)打开的 url? - How to detect the url opening from web browser(chrome) or webview(mobile app) using jquery/javascript in the website? 如果浏览器是android webview,如何使用javascript检测? - how to detect with javascript if browser is an android webview? 阻止网站加载到WebView中并在浏览器中打开 - Prevent website from loading in WebView and open in browser 如何在Android中检测WebView或浏览器 - how to detect webview or browser in android 如何使用JavaScript在WebView内打开移动浏览器上的窗口(弹出式窗口)? - How to open a window(poup) on mobile browser from inside a webview using javascript? 如何检测是否使用Android Browser或Android Native WebView Client - How to detect if using Android Browser or Android Native WebView Client 使用 PHP / Javascript 检测应用内浏览器 (WebView) - Detect in-app browser (WebView) with PHP / Javascript 使用javascript检测浏览器打开的其他窗口的URL - detect URL of the other windows open by a browser using javascript 使用javascript检测浏览器 - Using javascript to detect browser 如何使用Javascript检测浏览器的HTTP请求? - How to detect an HTTP request of a browser using Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM