How to detect if the user is accessing through a webview app

Asked

Viewed 553 times

0

Hello, I created a webview app for my site because it is 100% responsive and adapts well on mobile devices, but in my menu has a link to you download this app, I would like to know how I can identify a webview access because I want to hide this menu when using the webview app.

Ex: Menu do meu website

Where is MUFLIX PLAY, I would like to hide when accessed through webview :P

  • 1

    The width of the screen does not serve? Maybe the server side through the $_SERVER ["HTTP_USER_AGENT"] (php)

  • but and who accesses through the mobile browser ? wanted to identify when and when and when webview and browser to create a custom css :(

  • @Guilhermecostamilam there are browsers with the option to change the user agent

1 answer

0

Usually, to detect if a user is accessing the page in a iframe, with Javascript, is used window.top to check if it is equal to window current. That is, if window !== window.top for true, then the user is in a iframe. Does this also not work in your case? What if it is done, for example, in Javascript:

// Se estiver em um iframe...
if (window !== window.top) {

  // Adicionar a class "webview" no body...
  document.body.classList.add("webview");
}

...and in the CSS:

body.webview {
  /* Estilo aqui... */
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.