Tag Archives: javascript

Linux computer inside your browser

The subject I am writing about is the x86 emulator written in pure JavaScript and it works inside the browser.

The author of emulator is Fabrice Bellard also founder of QEMU, FFMPEG, Tiny C Compiler. You can test it from http://bellard.org/jslinux/.

On first glance I though that it’s just little window and seems like Linux terminal which supports basic unix commands. After testing it I saw that all unix commands and all programs inside this machine works as expected.

This is not any simulation nor emulation of linux, it’s really linux inside your browser. How?
As a web site it contains two JavaScript files. One of them is terminal program. Another is the emulation of x86 computer inside your browsers. So, pure javascript code emulates an x86 computer and the it loads real linux kernel image into this computer. Author didn’t write any linux software(vi, grep, ls etc. ) for this machine. Because it’s easy to find everywhere or compile them for x86 and those programs are inside the linux image which loaded into emulated x86 computer.

What will the next step? With little modification it’s possible to load FreeBSD, Solaris and even MS Dos into this machine.
With the help of HTML5 canvas and webGL will be possible to create emulation of graphic card. And with no doubt will be possible to load Windows, Linux X server etc. into this machine.

font-size and print “toolbar” :)

Sometimes users need to make the font size larger for easy reading the text. It happens usually in news portals or some web sites like the web site of my university www.bsu.edu.az.

And also it’s better to make the print version of the page. When saying print version it means that black text on white background without any styles and something else.

Let’s begin. Simply insert this code to your HTML page:

<script type="text/javascript" src="http://tpl.bdu.az/toolbar.js"></script>
<div style="text-align:right" id="adilToolbar">
<a href="javascript:adilTextDec('content')"><img src="http://tpl.bdu.az/images/font_size_less.png"/></a>
<a href="javascript:adilTextInc('content')"><img src="http://tpl.bdu.az/images/font_size_up.png"/></a>
<a href="javascript:adilTextPrint('content')"><img src="http://tpl.bdu.az/images/printer.png"/></a>
</div>

toolbar.js:

 
var adilTextSize = 100; // general variable for saving the current textsize by percents.
 
function adilTextInc(objid) {
	// I think to make the font size 200% larger is enough 
	if (adilTextSize <=200)	adilTextSize += 20; // increment by 20%
	document.getElementById(objid).style.fontSize = adilTextSize + '%';
}
 
function adilTextDec(objid) {
	if (adilTextSize >=80) adilTextSize -= 20; // decrement by 20%
        document.getElementById(objid).style.fontSize = adilTextSize + '%';
}
 
function adilTextPrint(objid) {
	// open new window
	var doc=window.open('','name','height=600,width=800');
 
	doc.document.write('<html><head><title>Print a page</title>');
	doc.document.write('</head><body>');
 
	// copy the content of the page
	doc.document.write(document.getElementById(objid).innerHTML);
 
	// remove out toolbar if it's there
 
	doc.document.write('<script type="text/javascript">');
	doc.document.write('try{document.getElementById(\'adilToolbar\').style.display=\'none\';}catch(e){}');
	doc.document.write('</script>');
 
	doc.document.write('</body></html>');
 
	// flush the input
	doc.document.close();
 
	// print the page
	doc.print();	
}

P.S. The button for decrement of the font-size is for eagles. :-P