I want to load another page from another page using javascript filereader(), how do I specify the parameter of the function according to the div ?
html code :
<!DOCTYPE HTML>
<html>
<body>
<div class='try1' onclick="openFile('test1.txt')">Show Test1</div>
<div class='try2' onclick="openFile('test2.txt')">Show Test2</div>
<div id='show_content'></div>
<script>
var openFile = function(event) {
var input = event;
var reader = new FileReader();
reader.onload = function(){
var text = reader.result;
document.getElementById("show_content").innerHTML = (reader.result.substring(0, 200));
};
reader.readAsText(input.files[0]);
};
</script>
</body>
</html>
I want it so that when :
1) I click div class='try1', it will load a file called 'test1.txt' into div id='show_content',
2) and when I click div class='try2', it will load a file called 'test2.txt' into div id='show_content'.
How do I achieve this ? I know I can use jQuery .load() function, but it turns out that jQuery .load() function need a server and uses xmlhttprequest to load, and I need to do this locally. Please if there's any better solution to achieve this, all answers are greatly appreciated. Thx