Roy Lee
Roy Lee

Reputation: 10842

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

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?

Upvotes: 0

Views: 2968

Answers (3)

Roy Lee
Roy Lee

Reputation: 10842

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.

Upvotes: 0

Talha
Talha

Reputation: 19262

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

Upvotes: 1

lukiffer
lukiffer

Reputation: 11303

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

Upvotes: 1

Related Questions