• Resolved nflor

    (@nflor)


    Hello there,

    first of all thanks for your amazing plugin!

    I installed your plugin and everything works on site side. I am also building an android app (via Flutter) and I am using webview in order to display single posts. The only problem is that, of course, the popup is showing on the app as well, while I would like to remove it. I should maintain popup visibility on mobile version of site, but not when using the app.

    How can I achieve that?

    Thank you in advance,
    nflor

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Brave

    (@getbrave)

    @nflor You can try this JS code to detect whether the site is being loaded through webview.

    var userAgent = window.navigator.userAgent.toLowerCase();
    if (userAgent.includes('wv')) {
        document.getElementsByTagName('body')[0].classList.add('body--webview');
    }

    The above code will add a body--webview class in the body of your flutter web version. Now that the class is added, you can simply add this custom css to hide all popups if the page is rendered in webview:

    .body--webview .brave_popup{display:none!important}

    P.S: If cannot add js code to your flutter app, read this:
    https://fireship.io/snippets/using-js-with-flutter-web/

    Hope this helps.
    Regards

    Thread Starter nflor

    (@nflor)

    Hi @getbrave

    thank you so much for your help. I’ve tried to add it through Code Snippets plugin as a script in the head tag, but does not work (applying CSS as well).

    I do not know PHP very well, but I found on the Internet another script. I added this in functions.php and combined with your JS:

    function add_codeToHead() {
    	if (strpos($_SERVER['HTTP_USER_AGENT'], 'wv') !== false) {
       $code = "<script> document.getElementsByTagName('body')[0].classList.add('body--webview'); </script>";
       echo $code;
    }
    }
    add_action('wp_head', 'add_codeToHead', 1);

    Still with same CSS, are there any errors in this PHP script?

    Thanks again,
    nflor

    Plugin Author Brave

    (@getbrave)

    @nflor The php code you shared is perfect, no flaw and does the same thing.

    How are you testing the app when you are building the app? Can you examine the html rendered in your flutter app and check if the class is being added to the body?

    Thread Starter nflor

    (@nflor)

    Hi @getbrave

    I examined the code and I get it in source code. If I do the opposite (from !== to ==) I can see it in web browser only, as it should do.

    If I test JS in console, it works, adding the class correctly.

    I guess that it has something to do with onload… I am trying different ways

    Thanks again,
    nflor

    Plugin Author Brave

    (@getbrave)

    Great to hear that. If you like the plugin, kindly help us grow by rating the plugin:
    https://wordpress.org/support/plugin/brave-popup-builder/reviews/#new-post

    Thanks

    Thread Starter nflor

    (@nflor)

    Hi @getbrave

    sure, I will do!

    I have just managed to fix applying this filter:

    add_filter( 'body_class', function( $classes ) {
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'wv') !== false){
    return array_merge( $classes, array( 'body--webview' ) );
    }else{
    return $classes;
    }});

    and then applying CSS 🙂

    Thank you so much again for your support, I am closing this thread
    nflor

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to avoid popup in an app webview?’ is closed to new replies.