: Html-JavaScript




Attach JavaScript loaded as part from an external html page

September 30th, 2010 admin Posted in Html-JavaScript Comments Off


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE>JavaScript On The Fly</TITLE>
 </HEAD>

 <BODY>

<input type="button" id="dialogOpener"  value="Show Dialog" onClick="handleDialogOpener();" />
<div id="dialog" style="position:absolute; width=200; height=200; left:100px; top:100px">
</div>

<SCRIPT LANGUAGE="JavaScript">
var dynamicConetnts = '<select name="number" onchange="handleNumberSelect(this);"><option value="1">one</option><option value="2">two</option><option value="3">three</option></select><script language="JavaScript">function handleNumberSelect(obj) {alert("selectedIndex = " + obj.selectedIndex);}<\/script>';
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
function handleDialogOpener() {

	var scriptInnerText = parseScriptInnerText(dynamicConetnts);

	var head = document.getElementsByTagName("head")[0];
	var scriptElement = createScriptElement(scriptInnerText);
	head.appendChild(scriptElement);

	document.getElementById('dialog').innerHTML = dynamicConetnts;
}

function parseScriptInnerText(scriptString) {
	scriptString = scriptString.substring(scriptString.indexOf("<script"));
	scriptString = scriptString.substring(scriptString.indexOf(">")+1);
	scriptString = scriptString.substring(0, scriptString.indexOf("<\/script>"));
	return scriptString;
}

function createScriptElement(scriptInnerText) {
	var scriptElement = document.createElement('script');
	var is_ie = navigator.userAgent.toLowerCase().indexOf("msie")!=-1?true:false;
	if (is_ie) {
		scriptElement.text = scriptInnerText;
	} else {
		var textNode = document.createTextNode(scriptInnerText);
		scriptElement.appendChild(textNode);
	}
	return scriptElement;
}

</SCRIPT>

 </BODY>
</HTML>
AddThis Social Bookmark Button

Object Oriented JavaScript

July 2nd, 2008 admin Posted in Html-JavaScript Comments Off

<script language="JavaScript">
function Person(first, last) {
	this.init(first, last);
}
Person.prototype.init = function(first, last) {
    this.first = first;
    this.last  = last;
};
Person.prototype.toString = function() {
	return this.first + " " + this.last;
}
Employee.prototype = new Person();
Employee.prototype.constructor = Employee;
Employee.superclass = Person.prototype;
function Employee(first, last, id) {
	Employee.superclass.init.call(this, first, last);
	this.id = id;
}
Employee.prototype.toString = function() {
	var name = Employee.superclass.toString.call(this);
	return this.id + ": " +  name;
}
var person = new Person("Muneeb", "Ahmad");
alert(person);
var employee = new Employee("Kevin", "Johnson", 1001);
alert(employee);
</script>
AddThis Social Bookmark Button

Auto Image Refresh

July 2nd, 2008 admin Posted in Html-JavaScript Comments Off

<script language="javascript">
function RefreshImage(){
document.webcam.src="http://yourdomain.com/webcam.jpg?a=" + String(Math.random()*99999999)
setTimeout('RefreshImage()',500);
}
</script>
<body onload="RefreshImage()">
<img name="webcam" src="http://yourdomain.com/webcam.jpg">
</body>
AddThis Social Bookmark Button

Add JavaScript at run time

June 15th, 2008 admin Posted in Html-JavaScript Comments Off

<SCRIPT LANGUAGE="JavaScript">
var sc=document.createElement('script');
sc.type='text/javascript';
sc.id="myscript";
sc.src="http://muneebahmad.com/scripts/aa.js" document.getElementsByTagName('head')[0].appendChild(sc);
</SCRIPT>
AddThis Social Bookmark Button

Similar Posts