UIWebView loading local js, CSS, img,html loading from the website

Source: Internet
Author: User

Resource files are placed under the root directory

1, index.html

<title>my Test page</title>
<link rel= "stylesheet" href = "test.css" type= "Text/css"/>
<script type = "Text/javascript" src = "22.js" ></script>
<body>
<H1 id= "food" onclick = "SayHello ()" >click me!
</body>

2, 22.js

function SayHello () {

if (document.getElementById (' foo '). InnerHTML = = ' Hi there ') {

document.getElementById (' foo '). InnerHTML = ' Click me! ' ;

}Else{

document.getElementById (' foo '). InnerHTML = ' Hi there ';

}

}

3, Test.css

body{

color:red;

background-color:#fff;

font-size:px;

font-style:italic;

font-weight:bold;

font-family: Arial;

}

4. OC Code

WEbview = [[uiwebview alloc] initwithframe: [[uiscreen mainscreen ] [ bounds]];

[self. View addsubview:iwebview];

[webview setbackgroundcolor: [uicolor whitecolor]];

NSString *path = [[NSBundle mainbundle] bundlepath];< /c19>

nsurl *baseurl = [nsurl fileurlwithpath:p ath];

    nsstring *imagestr=[ nsstring stringwithcontentsofurl:[ Nsurl urlwithstring:@ "http://192.168.1.155/ Index.html "" encoding:nsutf8stringencoding< span class= "s2" > error:nil];

[webview loadhtmlstring: Imagestr baseURL: BaseURL];

5, the principle is to first pull down the server HTML, and then load the local HTML by webview the way load,

UIWebView loading local js, CSS, img,html loading from the website

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.