0

I'm developing a C# application using Webkit.Net component. To be cleared, documentText is the only way to display dynamically generated HTML strings.

As title shown, is it possible to have something like this:

<script type="text/javascript" src="jss.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.js"></script>

on HTML Head section, to be included as part of the HTML string? I know in order to render image, I need to convert the images(from local file) into URi. So, how about javascript or jquery?

Roy Lee
  • 10,572
  • 13
  • 60
  • 84
  • can u explain more, r u trying to load/import html just as we included js files in header section of page? – Talha May 29 '12 at 04:50
  • Yes, Im trying to include js files at the header section of html page. And then, use loadHTML() function to display it in webkitbrowser. – Roy Lee May 29 '12 at 06:22

3 Answers3

1

All local references must be converted. If appropriate, I'd recommend using the <base> tag. See: http://www.w3schools.com/tags/tag_base.asp

lukiffer
  • 11,025
  • 8
  • 46
  • 70
1

you can use this javascript function to load js files in your header section...

function loadjscssfile(filename, filetype) {
            if (filetype == "js") { //if filename is a external JavaScript file
               // alert('called');
                var fileref = document.createElement('script')
                fileref.setAttribute("type", "text/javascript")
                fileref.setAttribute("src", filename)
                alert('called');
            }
            else if (filetype == "css") { //if filename is an external CSS file
                var fileref = document.createElement("link")
                fileref.setAttribute("rel", "stylesheet")
                fileref.setAttribute("type", "text/css")
                fileref.setAttribute("href", filename)
            }
            if (typeof fileref != "undefined")
                document.getElementsByTagName("head")[0].appendChild(fileref)
        }

Call this function as

loadjscssfile('http://code.jquery.com/jquery-1.5.js','js');
Talha
  • 18,898
  • 8
  • 49
  • 66
  • Just tried :) It doesn't worked for me. I would think importing JavaScript as similar as displaying an image in Webkit.Net C# webBrowser component. Which is to convert the image source into uri type first. – Roy Lee May 29 '12 at 07:04
  • No error, just the webkit.net webBrowser failed to include the js. Basically the js is to alert a message, but nothing shown. Do you awared that I'm actually talking about webkit.Net C#? Not the normal HTML web page? – Roy Lee May 29 '12 at 07:49
  • i am afraid you have to explore all the properties and methods of webKitBrowser object... – Talha May 29 '12 at 09:09
0

I discovered this cannot be done with .documentText, which is the only HTML strings supports in Webkit.Net.

In the latest Webkit wrapper: Open Webkit Sharp, it have got an API call, loadDocument(), whereby it display from the directory path of HTML file, JavasSript calling can be done locally in the HTML file.

Roy Lee
  • 10,572
  • 13
  • 60
  • 84