Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[b]<html>
<head>
<title>AJAX - loads a new script!</title>
<script type="text/javascript" src="ajax_lib.js"></script>
<style type="text/css">
#contents {
width : 500px;
height : 100px;
border : solid 1px #000;
}
</style>
</head>
<body>
<a href="javascript:send_request('loadme.html')">Try me!</a>
<hr />
<div id="contents">
</div>
</body>
</html>[/b]
[b]function hello() {
alert('Hello world');
}[/b]
[b]function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
ro = new ActiveXObject("Microsoft.XMLHTTP");
else
ro = new XMLHttpRequest();
return ro;
}
function send_request(html_file_name) {
server_side_script = 'html_loader.php?filename=' + html_file_name;
http.open('get', server_side_script);
http.onreadystatechange = handle_response;
http.send(null);
}
var http = createRequestObject();
function handle_response() {
if(http.readyState == 4){
var response = http.responseText;
var parts = response.split('[color red]~[/color]');
if(parts.length>1) {
load_script(parts[0]);
document.getElementById('contents').innerHTML = parts[1];
} else {
document.getElementById('contents').innerHTML = response;
}
}
}
function load_script(filename) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = filename;
document.getElementsByTagName('head')[0].appendChild(script);
}[/b]
[b]<?php
$file_name = $_REQUEST["filename"];
$html_file = file($file_name);
foreach($html_file as $lineno => $line)
echo $line;
?>[/b]
[b]new_script.js[color red]~[/color]<button onclick="hello()">Click me!</button>[/b]