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();")
 

Devv

Active Member
Licensed User
Longtime User
is the data coming from something you host yourself?


yes but i have small to no control over the content

1- i don't want to hide these elements for browser visitors (need to hide them only in my app webview)
2- i am using an eCommerce platform with caching it is very hard to modify the current html or css or JS
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
the problem is the way how things get executed by a browser and your injected js will be the last thing that will happen.

you could hide it via (inline) css then it is immediatly gone but then you have problems with your none app connections.

if it was an own product your could just send over a parameter to tell the backend it's coming from an app and then add the class hiding style to your html code.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Admittedly, I'm not well-versed in the WebViewExtras control, but could you not make the control .Visible=False before you execute the LoadURL and WaitFor the _PageFinished event to make the control .Visible=True? Or does your added JavaScript not re-trigger the PageFinished again?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
how can you hide something that doesn't even exist?

he wants to load a page and then hide the item before the page is displayed.

another option is download the code, change it and push it into the webview. but then session info wouldn't match.

if this happends as first thing in the app then there won't be an issue as session will be created from the moment you click a link.
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
thanks for replay guys

i had tried before to hide the web view until javascript is excited and it worked

but it is not suitable for my app

as it will make the browsing slower and it will not be beautiful to hide the webview on each click
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
@Jeffrey Cameron : ok, I get your point now. I thought you meant hiding the item and then load another page and hide it again after pageload.
but this is only valid for the first load then.
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
how can you hide something that doesn't even exist?

he wants to load a page and then hide the item before the page is displayed.

another option is download the code, change it and push it into the webview. but then session info wouldn't match.

if this happens as first thing in the app then there won't be an issue as session will be created from the moment you click a link.


yes i think this would be our last hope to download the page source with okhttp then modify html then load it to webview via htmlload

but it think this will cause problems sooner or later (specially that my website have caching and login features)
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User

Attachments

  • Screenshot from 2020-01-16 11-44-54.png
    Screenshot from 2020-01-16 11-44-54.png
    69.8 KB · Views: 229
Upvote 0

sorex

Expert
Licensed User
Longtime 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.
 
Upvote 0

Devv

Active Member
Licensed User
Longtime 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.

yes bro i already did that
it worked for the home page only
but the problem still remains with every page the user visit
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
if you can't enable it for every page load then you're almost out of options.

a last thing I can think of is reverse the logic.

you always hide those elements and check the platform with javascript and if it's not Android fade in or display those elements.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
the problem is that it executes when those items are already visible during the loading.

He wants to avoid that.
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
@sorex yes i know, since @Devv didn't tell us the url we can't try and see by the mean of "half of second... that make flicker quickly". I just wondering if using script above when execute on PageFinish is still flickering or not. 🤔

hello

here is the url
beisat.com
 
Upvote 0
Top