简体   繁体   中英

Load HTML Page inside CefSharp browser

I have an embedded chromium client named CefSharp in my Windows Form Application . On application start, I am loading a webpage in cefsharp from project resources using following statement in c#:

 web_view.LoadHtml(File.ReadAllText(@".\HelloPage.html"), @".\HelloPage.html");

Page loads successfully. Now I have a button on webpage and I want to navigate to another page designed using jquery-mobile and added to the project resources on this button's click event. I have a button and link on my web page to load another pages as following:

<a id="myLink" class="ui-btn ui-corner-all ui-shadow ui-mini" href="Page2.html" >Rollout</a>

<button type="submit" id="submitData" runat="server" onclick="Page3.html;" class="ui-shadow ui-btn ui-corner-all ui-mini">Submit</button>

Both the above mentioned events gives me Error Loading Page . I tried another technique to call c# method from javascript and make a call to load my page inside that method but couldn't achieve that. Can anybody please help me with this. Its my first project on c#. I want to know where I am doing wrong or what other options do I have to make it work. Thanks in Advance.

Dude it's miles off. I suggest try your code in a web page (hosted locally or remotely) that works. The above code:

onclick="Page3.html;"

Isn't going to work terribly well. Try and refer to a js function in onclick instead, the point is - get a working webpage first - preferably referring to external assets such as a js file and a css stylesheet.

Then you can look at cef packaging. Typically you'll need to set your web assets as embedded resources and access them using

Assembly.GetManifestResourceStream

but you're a long way from that yet. Concentrate on the webpage first.

改变这个;

<button type="submit" id="submitData" runat="server" onclick="window.location.href='Page3.html';" class="ui-shadow ui-btn ui-corner-all ui-mini">Submit</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM