Load website with local js/css - android

Is there a way to load someones website into webview, and then apply your css to it(that is stored in your app or some other server) ?
I have been searching for an answer for a month now, and nothing seems to work, i tried using some functions from WebView that load and store the html of the site and then load it with my url(or some similar solutions), the css is applied but then the sites javascripts dont work, the links are messed up and all sorts of problems occur.( also jsoap is not the answer, tried it, or maybe i didnt figure it out correctly )
Long story short, load www.some-site.com but make it use your css and remain fully functional?

Easily done with WebViewClient.shouldInterceptRequest.

Related

How can I override XMLHttpRequest in my Android WebView subclass so that scripts in head will use my overridden XHR?

I am working on what amounts to a custom android web browser and need to work around a bug in XHR.
I'd like to use a javascript XHR wrapper that fixes the bug (I already have the fix).
How can I force this to be loaded on every page load before anything else is loaded, including scripts in the head?
Note that arbitrary web content which I do not control will be loaded into my webview, so I can't do anything like load my script from the html page. I need to do something like intercept the first script request in head and synchronously inject my script. I'm not sure if this exact approach is possible - just trying to provide an example of the sort of approach that would satisfy my requirements.
I'm open to a completely different approach - I just know how to fix it via a javascript wrapper.
The details of the bug that I need to fix are not important, but just in case anyone is curious, successful XMLHttpRequests for non-android_asset file urls leave status set to 0 and statusText to "". Since some frameworks that use XHR treat status!=200 and/or statusText!="OK" as an error, I need to override the default behavior and return status=200 and statusText="OK" for successful XMLHttpRequests for non-android_asset file urls.
Since someone recently upvoted this and no one else offered any input, I'll share what I ended up doing to address the problem, even though it does not really address my original question.
In my case, I am only loading local (that is, dynamic files that are copied locally prior to being loaded into the webview) html files which I have access to via the filesystem prior to loading them into the webview. Therefore, I have an opportunity to modify the file prior to loading them. Since I could not find a better approach, I simply insert a script tag as first child of head in order to ensure that XHR override happens before anything else.
Feel free to comment if you want more details - I will do my best to answer!

Inconsistent DOM structure of the loaded HTML page in webview

I am making Highlighter for Android in WebView.
For the highlighting purpose, in one example i am using JQuery and Rangy, in another pure Javascript and XPath. I am trying the same Highlight in Desktop Browsers also.
Please refer to the previous questions which i posted for the problems which i am facing during Highlighting...
-->> Problem when using XPath
-->> Problem when using Rangy (Not answered yet!)
So... from the responses to these question, i came to the conclusion that
the DOM structure of the loaded HTML in WebView is inconsistent and different than that of the same HTML page loaded in Desktop Browser mostly with reference to "TextNodes"..
To support this conclusion, i have created a jsFiddle (link in the question).
But, i also think that WebView may not be changing the DOM structure but it surely returns incorrect TextNodes inside a div...
Now the question is, is there any way to stop this change in DOM structure of the HTML in WebView?
Any insight guys?

Android Webview css error

My android app loads into a webview a web application in a unique html.
My css is huge like 350kb. Sometimes in slow connections(mainly EDGE) not all the styles seems to load correct.
Some images (I am using data uris) are missing and some parts simply doesn't load the css styles.
I've tried to put the style inline in page (supposing that the css file got errors) but with no effect.
It seems like the android webview just stops the css parsing and shows the page.
Has anybody experienced something like this? How could I fix this in a nice way?
I have tested in Gingerbread only.
I think using of mobile app web-based is to be more lighter then the desktop equivalent, because of slower connection of this devices. Have you try to separate the css to see if this issue is because of big loading?

In Andorid, is it possible to get the Embed Html code of a YouTube video link?

I'm little bit struggle on past few days i can't get good solution for regarding this. My task is to load the youtube link in an webview. The given url is VideoLink. I directly load this link through android webview it won't play. When i load the embed code of this link, it successfully loaded. Here my problem is i get the embed code Manually (ie load the url on system browser-> right click -> select copy embed html),but i have lot of links like this. Is it not possible to do manually. Is it possible to get the embed html code of youtube link by programmatically.
Why cant you create a httpConection to the URL and read the InputStream in to String and give it to Webview. if you can explain a bit more, i can suggest you a better idea.

Android WebView Grid Display

I am having some problems with a webview I am using to access a specific URL within my Activity. When I load this exact same URL on a PC browser such as firefox, the edges of the grid are displayed
When I try to load the same URL from within my WebView by using
webView.loadURL("www.url.com");
I get the following grid.
Any ideas on how I can fix this? It's not a major issue, just annoying.
And this isn't real data, so don't worry about that.
I don't know that much about HTML so maybe this is an HTML issue?
Apologize for using imageshack, I can't post images yet.
Have you tried scrolling to the side? Does it display the images, then?
You might try the following:
Building webpages to support different screen densities
Take a look at the Android documentation there. It should give you a good example of how to get your data to display properly on any device.
Hope this helps!

Categories

Resources