Welcome Guest Search | Active Topics | Sign In | Register

CSS and JavaScript loading within LoadHTML content Options
David
Posted: Tuesday, August 25, 2015 12:18:07 PM
Rank: Member
Groups: Member

Joined: 11/4/2014
Posts: 12
Hi, There are a number of posts relating to this problem (which I've read at length) but I still can't fathom out exactly how to do the following. I need to load an SPA base local HTML page via LoadHTML. So, I get the path of the running assembly and figure out where the base html file lives. I read its content and pass this into LoadHTML - all works fine. However, this HTML content has .js and .css references as relative links, e.g. <link href="./CSS/TestStyle.css" rel="stylesheet" type="text/css"> and I can't work out what syntax I need to use in order for these relative links to be resolved correctly by the browser engine. I see that the LoadHTML has an overload for the baseURL but if I supply that argument I get a "The request was cancelled" error rendered in the WebView.

I have experimented with the TabbedBrowser example and I can get things to work with that, BUT the problem there is that I can't see how I can have a nicely organized web asset folder structure within my Visual Studio project that is picked up when I test run my application - i.e. the GetManifestResourceStream custom resource handler technique doesn't seem to be able to access anything that is not in the Debug folder of my project. Thanks, David.
eo_support
Posted: Tuesday, August 25, 2015 1:39:16 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

The overloaded version with baseUrl argument is for this scenario but it does not seem to be working correctly. We will look into it and get back to you as soon as possible.

Thanks!
eo_support
Posted: Wednesday, August 26, 2015 3:48:11 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

We have looked into this issue. The LoadHtml with baseUrl argument is the correct method for this purpose. However make sure the baseUrl terminates with "/". For example the following code would NOT work:

Code: C#
webView2.LoadHtml("&lt;img src='logo.gif' /&gt;", "http://www.essentialobjects.com/Images");


The correct code should be:

Code: C#
webView2.LoadHtml("&lt;img src='logo.gif' /&gt;", "http://www.essentialobjects.com/Images/");


In the first example, the baseUrl would be interpreted as "http://www.essentialobjects.com/" instead of as "http://www.essentialobjects.com/Images/".

Please let us know if this works for you.

Thanks!
David
Posted: Wednesday, August 26, 2015 4:56:23 PM
Rank: Member
Groups: Member

Joined: 11/4/2014
Posts: 12
Hi, unfortunately I still get the "The request was cancelled" error rendered in the WebView. All my content is local file-based - do you get the error when you try this? Thanks.
CPS
Posted: Wednesday, August 26, 2015 7:04:47 PM
Rank: Member
Groups: Member

Joined: 6/1/2015
Posts: 16
We found for anything local file based you normally need to turn off the same origin check (i.e. set EnableWebSecurity to false)

http://www.essentialobjects.com/doc/eo.webbrowser.browseroptions.enablewebsecurity.aspx
eo_support
Posted: Wednesday, August 26, 2015 9:28:26 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

Yes. CPS's suggestion is correct. You can try this code in your Program.Main before creating any WebView:

Code: C#
EO.WebBrowser.BrowserOptions options = new EO.WebBrowser.BrowserOptions();
options.EnableWebSecurity = false;
EO.WebBrowser.Runtime.SetDefaultOptions(options);


This will allow you to load local files. See here for more information on how to set browser options:

http://www.essentialobjects.com/doc/webbrowser/advanced/browser_options.aspx

Thanks!
CPS
Posted: Thursday, August 27, 2015 4:02:41 AM
Rank: Member
Groups: Member

Joined: 6/1/2015
Posts: 16
A 'Using Local Files' section might be a good addition to the help file, as this requirement is not very obvious?
eo_support
Posted: Thursday, August 27, 2015 1:01:07 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
CPS wrote:
A 'Using Local Files' section might be a good addition to the help file, as this requirement is not very obvious?


Thank you very much for the suggestion. We will see if such a switch exists inside Chromium's browser engine. If it does exist, we will have no problem exposing it. However if it does not exist, it probably would not be a good idea for us to try to add it.
CPS
Posted: Thursday, August 27, 2015 5:30:45 PM
Rank: Member
Groups: Member

Joined: 6/1/2015
Posts: 16
That's not what I meant, I meant updating the existing eoWebBrowser help to have a specific section called 'Using Local Files' that tells people that if you want to use local files you need to set EnableWebSecurity to false. Its not an obvious thing for a new user of EO to know, we certainly wasted a few hours before we knew this.
eo_support
Posted: Thursday, August 27, 2015 5:44:27 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Ah. That makes perfect sense. We will put that in our documentation. Thank you very much for your great suggestion!
David
Posted: Friday, August 28, 2015 1:09:50 PM
Rank: Member
Groups: Member

Joined: 11/4/2014
Posts: 12
Hi, I've been trying different combinations/techniques to find one that suits my purposes. The one I've settled on is to use a post-build action in Visual Studio to move my web assets into the debug/release folder so that the running application can find the HTML etc. I'm using a custom resource handler but I still cannot get the images/CSS/Script relative links to work in the HTML that I am loading. I have the EnableWebSecurity set to false. I have a very simple example project that I could let you have in order to work out what I'm doing wrong. How can I get this to you? Thanks, David
eo_support
Posted: Friday, August 28, 2015 1:40:32 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

Please see here for instructions on how to send test project to us:

http://www.essentialobjects.com/forum/test_project.aspx

Thanks!
eo_support
Posted: Friday, August 28, 2015 2:30:45 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

We have received and looked into your test app. The root of the problem is the path in your Desktop.html is invalid since there is no definition of root folder in your case. If your main Url is a file Url, then the base portion of that Url will be used as the root path. However in your case the main Url is a custom protocol "localapp://", so the browser engine has no way of figuring out the root folder for the file Urls.

If you use full path in your Url (for example, "file:///c:/TestSite/test.css"), then your code will work. So you may want to include some special token such as "[ROOTFOLDER]" in your HTML file, and then replace that with your actual root folder in your ProcessRequest. That way the browser engine will receive full path and it will display everything properly.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.