PDA

View Full Version : How to skip onclick button on window.onload


fab26x
05-29-2009, 02:49 AM
Hello Guys, Sorry I'm not a good Coder, I'm just starting to learn... I have an issue with a small code. Happens that when page loads there is button that come alive(TEST). After clicking on the test button, the script will do it's magic. What I'm trying to do is, to skip the test button and have the script just run on once page is loaded from server. window.onload.

[CODE]
<style>
#mbox{background-color:#eee; padding:8px; border:2px outset #666;}
#mbm{font-family:sans-serif;font-weight:bold;float:right;padding-bottom:5px;}
#ol{background-image: (overlay.png);}
.dialog {display:none}

* html #ol{background-image:none; filter: progid: DXImageTransform.Microsoft.AlphaImageLoader(src="overlay.png", sizingMethod="scale");}


</style>
<title>O Fabio é um Mané !!!</title>
</head>
<body scroll="no">
<script language="JavaScript" type="text/javascript">
// Modal Dialog Box
// copyright 8th July 2006 by Stephen Chapman
// http://javascript.about.com/
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function $(x){return document.getElementById(x);}
function scrollFix(){var obol=$('ol');obol.style.top=posTop()+'px';obol.style.left=posLeft()+'px'}
function sizeFix(){var obol=$('ol');obol.style.height=pageHeight()+'px';obol.style.width=pageWidth()+'px';}
function kp(e){ky=e?e.which:event.keyCode;if(ky==88||ky==120)hm();return false}
function inf(h){tag=document.getElementsByTagName('select');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;tag=document.getElementsByTagName('iframe');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;tag=document.getElementsByTagName('object');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;}
function sm(obl, wd, ht){var h='hidden';var b='block';var p='px';var obol=$('ol'); var obbxd = $('mbd');obbxd.innerHTML = $(obl).innerHTML;obol.style.height=pageHeight()+p;obol.style.width=pageWidth()+p;obol.style.top=posT op()+p;obol.style.left=posLeft()+p;obol.style.display=b;var tp=posTop()+((pageHeight()-ht)/2)-12;var lt=posLeft()+((pageWidth()-wd)/2)-12;var obbx=$('mbox');obbx.style.top=(tp<0?0:tp)+p;obbx.style.left=(lt<0?0:lt)+p;obbx.style.width=wd+p;obbx.style.height=ht+p;inf(h);obbx.style.display=b;return false;}
function hm(){var v='visible';var n='none';$('ol').style.display=n;$('mbox').style.display=n;inf(v);document.onkeypress=''}
function initmb(){var ab='absolute';var n='none';var obody=document.getElementsByTagName('body')[0];
var frag=document.createDocumentFragment();var obol=document.createElement('div');obol.setAttribute('id','ol');obol.style.display=n;obol.style.posi tion=ab;obol.style.top=0;obol.style.left=0;obol.style.zIndex=998;obol.style.width='100%';frag.append Child(obol);
var obbx=document.createElement('div');obbx.setAttribute('id','mbox');obbx.style.display=n;obbx.style.po sition=ab;obbx.style.zIndex=999;
var obl=document.createElement('span');obbx.appendChild(obl);
var obbxd=document.createElement('div');obbxd.setAttribute('id','mbd');obl.appendChild(obbxd);frag.inser tBefore(obbx,obol.nextSibling);obody.insertBefore(frag,obody.firstChild);
window.onscroll = scrollFix;
window.onresize = sizeFix;
}

window.onload = initmb;

var x = 'something to check';
$('txt').innerHTML = x;
sm('box',200,50);
function OKSelected() {
var y = x;
}


</script>



<div id="box" class="dialog">
<div style="text-align:center"><span id="txt">Press OK to continue.</span><br>
<button onclick="hm('box');okSelected()">OK</button></div>
</div>
<br><h1>Page Block</h1>
<button onclick="sm('box',250,50);">TEST</button>


</body>
[CODE]

If you test this code, you will see after pressing the button (TEST), a modal dialog box will show up, after pressing the OK button things will come back to normal. What I'm trying to do is, skip the first button (TEST) and have the page load and the "modal dialog box" comes alive right away once the page loads up. Any help would be great. Basically, result would be, page loads up "modal dialog box" is activated.
No need to press (TEST) Button, it has to be hidden or non existent. Thank you for the help.

KenZag
05-29-2009, 06:10 AM
Should it be
window.onload = initmb();
or try
<body onload="initmb();" ...
instead.

Ken

_Aerospace_Eng_
05-29-2009, 07:00 AM
Just change this
window.onload = initmb;

var x = 'something to check';
$('txt').innerHTML = x;
sm('box',200,50);
function OKSelected() {
var y = x;
}
to this
window.onload = function()
{
initmb();

var x = 'something to check';
$('txt').innerHTML = x;
sm('box',200,50);
}
function OKSelected() {
var y = x;
}

fab26x
05-30-2009, 05:54 PM
Hello,

I tested the code you gave and it works. Thank you... really helped. Now, I'm just working the kinks to get it working on the site. Enjoy the weekend and thank you once again...

Fabio