Adding css or script files to all pages.

Having problems with building or using the CefGlue .NET/Mono binding? Ask your questions here.

Moderator: fddima

Adding css or script files to all pages.

Postby Desu » Wed Jul 10, 2013 6:47 pm

Hello,
I am looking for ways to add a css and a js file to all pages loaded in my cef app.
Any pointers where i might start?
I am thinking adding them to after page loaded but not sure if thats the right approach or how would i do it.

Thanks.
Desu
Techie
 
Posts: 11
Joined: Mon Jun 24, 2013 3:05 pm

Re: Adding css or script files to all pages.

Postby fddima » Thu Jul 11, 2013 3:16 am

Hi.

There is depended from what source you get pages (i.e. you are owner of them or not).
If you not owning them - then i think, that it is easiest way do this after document loaded, and via ExecuteJavaScript method execute js code, which will do any ramaining work.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Adding css or script files to all pages.

Postby Desu » Thu Jul 11, 2013 7:01 am

I load pages locally from file:/// urls,
Let's say user browses for the files with a file open dialog and selects them. So i do not create files myself. Going to try adding with javascript.
Desu
Techie
 
Posts: 11
Joined: Mon Jun 24, 2013 3:05 pm

Re: Adding css or script files to all pages.

Postby fddima » Thu Jul 11, 2013 7:11 am

Desu wrote:I load pages locally from file:/// urls,
Let's say user browses for the files with a file open dialog and selects them. So i do not create files myself. Going to try adding with javascript.

Alternative way - it is load resources via own scheme handler, and inject css/script code on-the-fly, but there is will require minimal html parsing.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: Adding css or script files to all pages.

Postby Desu » Fri Jul 12, 2013 6:11 pm

I decided to go the javascript way because of the possibility of an android version of same project which will use native webviews.

I found a way which i assume is pretty efficient(but it maybe something that should be avoided) but i would like your opinion whether i should keep it this way or use a custom request handler instead.

I use a custom load handler and in OnLoadStart i read jQuery to a String from file and pass that string to ExecuteJavascript on the frame. And then i execute "ijq = $.noConflict();" on a second ExecuteJavascript because of the possiblity of jQuery already being included in the html file that is being loaded. That should make ijq available as jQuery in all loaded pages right?

Or would i see a conflict if page loads fast and if page's own jquery is already loaded by the time my second executejavasciprt is called? (I mean is that even possible)
Desu
Techie
 
Posts: 11
Joined: Mon Jun 24, 2013 3:05 pm


Return to CefGlue Forum

Who is online

Users browsing this forum: No registered users and 28 guests