Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

How to turn the white border into black when fullscreen in browser

edited May 2023 in OSWeb

Hello everyone,

In my experiment, I want participants to press F11 to fullscreen the browser before they start my experiment. However, the outside area will be white (see my screenshot) when I test it. Does anyone know how to turn that white border into black? My OpenSesame version is 3.3.14 and OSWeb is 1.4.13.1.

Thanks ahead.

(click the picture and you will see the white border)

Comments

  • Hi @Siyang,

    One solution would be to chage the resolution of your experiment to match your screen's resolution. n my case, my screen is set to 4K, so the following settings will make the whole screen black after I press F11 in the browser:

    However, this solution is not entirely satisfactory because it means you may have to scale up all of your stimuli pictures, your text etc. so that it doesn't look too small. Also, it would mean having to do so again if you then decided to run the experiment on another computer using another resolution. Third, if you're planning to run this online, this is not suitable because you can't know what screen reolution the participants will have.

    Hence, I'd recommend an alternative using some Javascript coding:

    When running an experiment in the browser, you can use Javascript to modify aspects of the HTML document. While I don't think you can get rid of the white present on the very initial page (OSWeb's welcome screen), you can for everything else that follows.

    All you need to do is to insert the following Javascript in an inline_javascript at the beginning of the experiment:

    document.body.style.backgroundColor = 'black';
    

    That will change the background color of the HTML page.

    Since you mentionned that you're asking participants to press the F11 key to make the task full screen, you may also be interested in the folowing piece of code (that you can insert in the same inline_javascript obbject as the above):

    // maximizes window automatically
    // Detects browser
    var browser = navigator.userAgent;
    if (browser.indexOf('Chrome') > -1) {
    vars.browser="Chrome/Edge"
    } else if (browser.indexOf('Safari') > -1) {
    vars.browser="Safari"
    } else if (browser.indexOf('Firefox') > -1) {
    vars.browser="Firefox"
    } else if (browser.indexOf('Opera') > -1) {
    vars.browser="Opera"
    } else if (browser.indexOf('MSIE') > -1) {
    vars.browser="Microsoft Internet Explorer"
    } else {
    vars.browser="Unknown browser"
    }
    
    // Detects if full screen mode is available
    if (document.fullscreenEnabled) {
    vars.fullscreen="Fullscreen mode is supported."
    } else {
    vars.fullscreen="Fullscreen mode is not supported."
    }
    
    function setFullScreen() {
    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);
    }
    }
    }
    
    // if browser supports full screen mode,switch to it.
    if (document.fullscreenEnabled=true) {
    setFullScreen()
    }
    

    This code will set the task ton full screen automatically. It should work with most browsers. If you want to be absolutely certain, you can always display a message to participants asking them to press F11 is the task is not currently in full screen mode.

    Here's a comparison without and with the code described above:

    Note thata simpler way to automate the full screen presentation is to use OSWeb's "Make browser fullscreen" option:

    This will work for most tasks but in my experience, it generates problems with tasks using forms e.g., form_textinput); in such tasks, the forms can be unresponsive because browsers have security features that disable text input. So if you task does not use forms, this simple method should work. If it does, or if you notice that the task is unresponsive when made full screen using this method, use the code I insrted above.

    Here's my example so that you can't copy and paste the code and see exactly where it goes:

    Best,

    Fabrice.

    Buy Me A Coffee

  • Hi @Fab,

    My code works now. Thank you so much!

    I am basically a beginner at javascript, would you mind telling me where to learn these things about website settings that could work in OpenSaseme or OSWeb?

    Thanks again,

    Siyang.

  • Hi @Siyang,

    I'm no Javascript expert myself. I usually do basic searches in Google. the W3school website can be a good place to start (https://www.w3schools.com/js/).

    Best,

    Fabrice.

    Buy Me A Coffee

  • Hi @Fab ,

    Thank you for your reply!

    Best regards,

    Siyang

Sign In or Register to comment.