Webkit.Net C#: How to import JavaScript in HTML

2.9k views Asked by At

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?

3

There are 3 answers

0
Roy Lee On BEST ANSWER

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.

1
lukiffer On

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

3
Talha On

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');