-
-
Save dineshmm23/e991bfc00f1430658d6001692fc41a7d to your computer and use it in GitHub Desktop.
Get a local html file to insert into your Cordova Single Page Application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Get local html files (views/widgets) to insert into your SPA | |
@param path ex: | |
path = 'file:///android_asset/www/view/page.html' | |
@param success | |
@param failure | |
*/ | |
function get_html_file(path, success, failure) { | |
const xhr = new XMLHttpRequest() | |
xhr.open('GET', path) | |
xhr.onload = () => { | |
if (xhr.status == 200) | |
success(xhr.response) | |
else if (failure) | |
failure(xhr.status) | |
} | |
xhr.send() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> | |
<body> | |
<div id="container"></div> | |
</body> | |
<script src="js/get_html_file.js"></script> | |
<script src="js/page.js"></script> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="page"> | |
<ul> | |
<li></li> | |
<li></li> | |
<li></li> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
@file page.js | |
@description View | |
*/ | |
const page = (() => { | |
function load() { | |
get_html_file('file:///android_asset/www/view/page.html', data => { | |
document.querySelector('#container').innerHTML = data | |
}) | |
} | |
return { | |
load: load | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment