<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8"/>
<title>Testing</title>
<script type="text/javascript">
function mouseClick(element, sx, sy,cx, cy) {
//var element = document.getElementById("btn");
var d = element.ownerDocument;
var obj = {
type: "click",
canBubble: true,
cancelable: true,
view: d.defaultView,
detail: 1,
screenX: sx,
screenY: sy,
clientX: cx,
clientY: cy,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
button: 1,
relatedTarget: null
};
var evt;
//console.log(obj);
//return;
//document.getElementById("txt").textContent = "none";
//var str = "";
//for (var property in obj)
// str = str + property + ", ";
//console.log(str);
if (d.createEvent){
// dispatch for firefox + others
evt = d.createEvent('MouseEvents');
evt.initMouseEvent(obj.type, obj.canBubble, obj.cancelable, obj.view,
obj.detail, obj.screenX, obj.screenY, obj.clientX, obj.clientY,
obj.ctrlKey, obj.altKey, obj.shiftKey, obj.metaKey, obj.button, obj.relatedTarget);
evt.isTrusted = true;
//document.getElementById("txt").textContent =
element.dispatchEvent(evt);
console.log(evt);
}else
if(d.createEventObject) {
// dispatch for IE 9+
evt = document.createEventObject();
for (var property in obj)
evt[property] = obj[property];
//document.getElementById("txt").textContent =
element.fireEvent('onclick', evt);
console.log(evt);
}
}
function pushme() {
var x = document.getElementById("txt");
//setTimeout(function(){
x.textContent = "button clicked!";
//}, 1000);
}
function clickevent(event) {
var element = document.getElementById("btn");
var x = document.getElementById("txt");
if(element.click) // IE 9+, FF, Chrome, opera
{
x.textContent = "element.click()";
}else
if(MouseEvent)
{
x.textContent = "MouseEvent";
}else
if(document.createEvent)
{
x.textContent = "document.createEvent";
}else{
x.textContent = "unknown!";
}
}
var msg;
function init(event) {
var txt = document.getElementById("txt");
var btn = document.getElementById("btn");
//console.log(x);
//btn.click();
//clickevent(event);
txt.textContent = msg; //"init";
mouseClick(btn, 0, 0, 0, 0);
}
function ElementOnLoad(el, func) {
if(el.addEventListener) { // IE 9+
el.addEventListener("load", func, false);
msg = "addEventListener, I'm ready!";
}else
if(el.attachEvent) {
el.attachEvent("onload", func);
msg = "attachEvent, I'm ready!";
} else
{
el.onload = func;
msg = "onload, I'm ready!";
}
}
//var ready = document.getElementById("ready");
function fnStartInit() {
if (document.readyState === "complete") {
var txt = document.getElementById("txt");
var btn = document.getElementById("btn");
txt.textContent = /*msg;*/ "I'm ready!";
mouseClick(btn, 0, 0, 0, 0);
}
}
if(document.attachEvent) {
document.attachEvent("onreadystatechange", fnStartInit);
} else {
document.onreadystatechange = fnStartInit;
}
//onload = "init(event)"
//ElementOnLoad(window, init);
</script>
</head>
<body>
<div class="container">
<div class="row">
<h2 id="txt">waiting.. ukdj</h2>
<img id="ready" src="https://s-media-cache-ak0.pinimg.com/736x/5f/bf/7e/5fbf7ea07bdf337526300cc0836e6cbd.jpg"></img>
<button type="button" id="btn" onclick="pushme()">push me</button>
</div>
</div>
<script type="text/javascript">
//ElementOnLoad(window, init);
</script>
</body>
</html>