Android Question Hiding html element from webview before page load

Devv

Active Member
Licensed User
Longtime User
Hello

i am trying to hide an element before the page load

i tried using webview extras to inject JS on page finished
it worked, but there is about half of a second the element is visable until JS is executed (the element flicker quickly)

how can i hide that element before the page load so it wont appear at all ?

B4X:
WebViewExtra.ExecuteJavascript("document.getElementsByClassName('customer-signin-module')[0].remove();")
 

sorex

Expert
Licensed User
Longtime User
I see that you can set the useragent string with the webviewsetting library.

then you can set it to "androidapp" or something and with a small mod in the php code you can add an extra class or style to those 4 objects to hide them when the useragent is "androidapp".

All other options client options won't help as they occur when the content is already shown (unless you force the (pre)loading overlay on every page)
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
I see that you can set the useragent string with the webviewsetting library.

then you can set it to "androidapp" or something and with a small mod in the php code you can add an extra class or style to those 4 objects to hide them when the useragent is "androidapp".

All other options client options won't help as they occur when the content is already shown (unless you force the (pre)loading overlay on every page)

ok thanks for your help bro
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
this works fine and shows test on my desktop and nothing on my android phone.
so you just need to add it to your template files and the relevant <ul> or <div> (the 2 lines of code is only needed once)

B4X:
Sub Globals
    Dim wv As WebView
    Dim wvs As WebViewSettings
End Sub

Sub Activity_Create(FirstTime As Boolean)
    wv.Initialize("wv")
    wvs.setUserAgentString(wv,"androidapp")
    wv.LoadUrl("http://mytesturl/test.php")      
    Activity.AddView(wv,0,0,100%x,100%y)
End Sub

PHP:
<?php
$hideStyle="";
if($_SERVER['HTTP_USER_AGENT']=="androidapp"){$hideStyle="style='display:none'";}
?>

<div <?php echo $hideStyle?>>test</div>
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
this works fine and shows test on my desktop and nothing on my android phone

B4X:
Sub Globals
    Dim wv As WebView
    Dim wvs As WebViewSettings
End Sub

Sub Activity_Create(FirstTime As Boolean)
    wv.Initialize("wv")
    wvs.setUserAgentString(wv,"androidapp")
    wv.LoadUrl("http://mytesturl/test.php")      
    Activity.AddView(wv,0,0,100%x,100%y)
End Sub

PHP:
<?php
$hideStyle="";
if($_SERVER['HTTP_USER_AGENT']=="androidapp"){$hideStyle="style='display:none'";}
?>

<div <?php echo $hideStyle?>>test</div>

thanks for the example
but unfortunately it is not easy to implement this solution

as i am using prestashop which would requite doing lots of customization to the code to do this

that is why i was searching for client solutions
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
stuff like that should be in include files. the only problem is updates of prestashop then they will probably be gone again.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Have you tried Overriding the Url, downloading the page text and updating it before displaying as HTML?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Something like this:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    WebView1.LoadUrl("http://beisat.com/en/")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub WebView1_OverrideUrl (Url As String) As Boolean
    Log(Url)
    
    Dim Job As HttpJob
    Job.Initialize("Job",Me)
    Job.Download(Url)

    
    Return True
End Sub

Private Sub JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
        Log("Loading")
        '
        'Add your script block before displaying
        '
        WebView1.LoadHtml(j.GetString)
    End If
End Sub
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
Something like this:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    WebView1.LoadUrl("http://beisat.com/en/")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub WebView1_OverrideUrl (Url As String) As Boolean
    Log(Url)
   
    Dim Job As HttpJob
    Job.Initialize("Job",Me)
    Job.Download(Url)

   
    Return True
End Sub

Private Sub JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
        Log("Loading")
        '
        'Add your script block before displaying
        '
        WebView1.LoadHtml(j.GetString)
    End If
End Sub


thanks for the example
yes i had tried this earlier

it works but then back and forward buttons will not work

plus login and caching might not work
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
Won't that create multiple sessions?

also postings inbetween will get lost.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You could maintain your own lists of URL's to implement Back and forward, The only way to find out if login and caching works is to try it.
 
Upvote 0

rraswisak

Active Member
Licensed User
Can you enable a preloading animation in the webshop?

Than you can abuse that to remove those elements before you hide the preloading overlay.

i just implemented @sorex idea at post #13 by adding panel over webview, while the page in progress the panel will shown and hide when page was finish, i can see this works for every page i opened, but you still can see flickering element what you want to hide, at least user can't tap the element while in visible. You can add text or gif animation on the panes indicating the page is in progress.

B4X:
Sub Globals
    Private xui As XUI
    Private WebView1 As WebView
    Private we As WebViewExtras
    Private p As B4XView
    Private inProgress As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("a")
    ShowProgress
    WebView1.LoadUrl("https://beisat.com/en/")
End Sub

Sub WebView1_PageFinished (Url As String)
    we.executeJavascript(WebView1,"document.getElementsByClassName('customer-signin-module')[0].style.display = 'none';")
    we.executeJavascript(WebView1,"document.getElementsByClassName('left-nav-trigger')[0].style.display = 'none';")
    we.executeJavascript(WebView1,"document.getElementsByClassName('shopping-cart-module')[0].style.display = 'none';")
    we.executeJavascript(WebView1,"document.getElementsByClassName('language-selector-wrapper')[0].style.display = 'none';")
    p.SetVisibleAnimated(0,False)
    p.RemoveViewFromParent
    inProgress =False
End Sub

Sub WebView1_OverrideUrl (Url As String) As Boolean
    ShowProgress
End Sub

Sub ShowProgress
    If inProgress = True Then Return
    inProgress = True
    p = xui.CreatePanel("pnl")
    p.Color = xui.Color_ARGB(150,255,255,255)
    Activity.AddView(p,WebView1.Left, WebView1.Top, WebView1.Width, WebView1.Height)
    p.SetVisibleAnimated(0,True)
End Sub

Sub pnl_Click
  
End Sub
 
Last edited:
Upvote 0
Top