Automatic click along with full screen

Asked

Viewed 764 times

6

I have a website, and on the site the user when logging in will enter a page and this page should be full screen automatically without the user needing to click something.

I read that it is not possible for the browser to stay full screen without the permission of the user, so I thought to put an automatic click on the site as soon as the user enters, but still does not leave.

The code I have:

JS:

document.getElementById('teste').click();

    function toggleFullScreen() {
  if (!document.fullscreenElement &&    // alternative standard method
      !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement ) {  // current working methods
    if (document.documentElement.requestFullscreen) {
      document.documentElement.requestFullscreen();
    } else if (document.documentElement.msRequestFullscreen) {
      document.documentElement.msRequestFullscreen();
    } else if (document.documentElement.mozRequestFullScreen) {
      document.documentElement.mozRequestFullScreen();
    } else if (document.documentElement.webkitRequestFullscreen) {
      document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
    }
  } else {
    if (document.exitFullscreen) {
      document.exitFullscreen();
    } else if (document.msExitFullscreen) {
      document.msExitFullscreen();
    } else if (document.mozCancelFullScreen) {
      document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
      document.webkitExitFullscreen();
    }
  }
}

HTML:

<button id="teste" onClick="toggleFullScreen();"></button>

Is there any way I can do this?

  • To log in, the user probably has to click some button, right? You could take advantage of the very action of this button to activate the full screen.

  • I already tested it and it won’t because it directs to another screen

  • Good afternoon Maria, is there anything else that you think I should include in the answer? It became understandable to you?

2 answers

3

This is unfeasible, first because if it were possible I really as a user would refuse to browse several websites, which would use this indiscriminately, many lay users would get lost without knowing what to do or angry, the API itself is determined to be like this, the user decides what he wants and what is best for him.

Force an automatic click will also not work, the browser knows very well the difference between when the click is simulated via JS and when it is done by the user (or software that simulates the user).

The browser is the user’s, so the intention to use a browser is to be able to use the tabs and windows, actually with the forgiveness of the word, but this force the fullscreen is perfumery, browsers are not ultimate software for exclusive use, the premise is the same that responded in:

I’ll take the part that matters to understanding:

...if to use in an internal system (enterprise system) then you should think of a solution less "WEB", at least in the case of this specific situation, since display on another screen really seems a very specific need and would probably not be for all users.

I’m not just saying, run for the mountains, abandon the WEB, not that, I understand that there are many people who are on the web by practicality, for the ease of running the application in several devices, but there are solutions to the world of HTML and Javascript easy and uncomplicated way without having to appeal to things like C++, Python, Java and be required to learn something new, an example great of this is the Electron:

With it it is possible to create desktop applications with HTML technologies, css, js and that will run on various platforms.

High-use applications use such technology, such as:

  • Github Desktop

  • Skype

  • Atom

  • Visualstudio Code

So simply if you want to create a software for enterprise and limit user access to this software, eletron or a platform that uses webViews, like Qt, or those "derivatives" with Webkit (technology used in Safari and on some mobiles) like Webkitgtk+ (Qt is C++, GTK is C but will probably be able to use with C++), of course Eletron for who is more Web will be a much less painful path.

Electron fullscreen

An example found in this link https://electronjs.org/docs/api/browser-window#browserwindow-setfullscreen-flag, should look like this:

const {BrowserWindow} = require('electron')

let win = new BrowserWindow({ fullscreen: true })
win.on('closed', () => {
    win = null
})

win.loadURL('https://seusite.com/login')

To create the "executable" (deploy), read this:

For Windows and Macos things are different

0

On the occasion of using one <button> uses this event in your HTML:
<body onClick="toggleFullScreen();">
This means that if the user clicks on any part of the screen the Fullscreen mode will be activated.
This is the simplest way not to have to see this mistake:
Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture.

Another solution I found was:

var src = "https://google.com";
window.open(src,"newWin","width="+screen.availWidth+",height="+screen.availHeight);

but in that case the browser will open a new maximized window, I know that is not yet what you want, but I am searching.

  • That’s not what I need, I need him not to have to click anything to make it happen

  • I understood what you need, I also had this need a while ago, but I still haven’t found the solution

Browser other questions tagged

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