I've tested it in most recent versions of IE, FF, Opera, and Safari.
The first parameter is the alert's text, if a second parameter is passed, it is the alert's title, else it will just have "Alert" in the title.
You can fire the function as many times as you like, any alert's thrown after the first will set themselves on top of each other slightly staggered much like the built in alert.
The alert will automatically be placed in a visible place regardless of where the page has scrolled. They will also stay in that same place in relation to the screen if the user scrolls after the alert has fired.
The top most alert is the only one clickable and moveable until it has been acknowledged (Much like a regular alert).
The benefit of this is that it does not freeze the user's interface once the alert is thrown.
Here's the code:
Javascript:
//*****************************
// Custom Alert Box
// Free to use with credits in tact.
// Written By Adam Matthews aka Basscyst
//AdamDMatthews@Gmail.com
//*****************************
function msgBox(msg,hdr){
if(!document.getElementById('alerts')){
var div=document.createElement('div');
div.setAttribute('id','alerts');
document.body.appendChild(div);
}
var div=document.createElement('div');
div.className="alertbox";
var h3=document.createElement('h3');
h3.className="alerttitle";
var p=document.createElement('p');
p.className="alerttxt";
var footdiv=document.createElement('p');
footdiv.className="alertfoot";
div.appendChild(h3);
div.appendChild(p);
div.appendChild(footdiv);
var but=document.createElement('input');
but.setAttribute('type','button');
but.className='alertbut'
but.setAttribute('value','OK');
footdiv.appendChild(but);
var hdr=(hdr) ? hdr : "Alert!";
h3.appendChild(document.createTextNode(hdr));
var cut=msg.split("
");
var len=cut.length;
p.appendChild(document.createTextNode(cut[0]));
for(var i=1;i<len;i++){
p.appendChild(document.createElement('br'));
p.appendChild(document.createTextNode(cut[i]));
}
document.getElementById('alerts').appendChild(div);
window.onscroll=function(){
placeAlerts();
}
window.onresize=function(){
placeAlerts();
}
placeAlerts();
}
var posX;
var posY;
function mouseXY(e){
if (!e){
var e = window.event;
}
if (e.clientX)
{
posX = e.clientX + document.documentElement.scrollLeft;
posY = e.clientY + document.documentElement.scrollTop;
}
else
{
posX = Math.max(e.pageX,0);
posY = Math.max(e.pageY,0);
}
var coord=new Array();
return coord;
}
if(document.captureEvents){
document.captureEvents(Event.MOUSEMOVE)
}
function placeAlerts(){
var alerts=document.getElementById('alerts').getElementsByTagName('div');
var len=alerts.length;
var x=0;
var y=300;
var w=document.body.clientWidth;
var h=document.body.clientHeight;
for(var i=0;i<len;i++){
alerts[i].style.zIndex=i+100;
alerts[i].getElementsByTagName('h3')[0].onmousedown="";
alerts[i].getElementsByTagName('input')[0].onclick="";
if(window.pageYOffset){
alerts[i].style.top=y+(window.pageYOffset)+'px'
}else{
alerts[i].style.top=y+(document.documentElement.scrollTop)+'px'
}
alerts[i].style.left=(w / 2)- (343 / 2) + x +'px';
x=x+15;
y=y+15;
if(i==len-1){
var h3=alerts[i].getElementsByTagName('h3')[0];
var but=alerts[i].getElementsByTagName('input')[0];
but.onclick=function(){
this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
var alerts=document.getElementById('alerts').getElementsByTagName('div');
if(alerts.length==0){
window.onscroll="";
}
placeAlerts();
}
h3.onmousedown=function(event){
this.parentNode.setAttribute('id','active_alert');
var event=(event)?event:arguments[0];
mouseXY(event);
start_x=posX;
start_left=document.getElementById('active_alert').style.left.replace('px','');
adjust=posX-start_left;
document.onmousemove=function(event){
var event=(event)?event:arguments[0];
mouseXY(event);
var obj=document.getElementById('active_alert');
obj.style.left=posX-adjust+'px'
obj.style.top=posY-5+'px'
};
}
h3.onmouseup=function(){
document.onmousemove="";
this.parentNode.setAttribute('id','');
}
}
}
}
Function Call
msgBox("You have done something real bad!
So Bad, oh so bad!","Ya shoudn't of done it boy!")
I was wandering how would I make my own version of "alert()", or prompt(). I see jquery (i think) has something like this. But I'd like to make it myself, for the perpuse of getting experince. So, first problem is, I'm not sure how would I temporary "lock background", so that when your own alert shows, you must select ok. Is there maybe any function in JS that allows this (to lock temporary website expect certain elements (which would be div in this example, that would contain my alert box) or in other words, make site unavailable to you until you press OK button on your custom made alert (div element or something) message)?
Code: <script language="JavaScript"> var checkobj function agreesubmit(el){[code]....
i need to make it like if the button is clicked and there the agreement checkbox is not checked.. it should give an alert that the alert is not checked.. i know that would require a if and else statement but i cant figure out how to do it
i am facing a problem after using jquery jconfirm alert. Issue is that after receiving confirm alert, when user press tab to go on Cancel button and press Enter key there, despite of firing event of Cancel button, it fires the event of OK button. this issue is not produced when user press the cancel button by mouse. Waiting for your replies.
php page is echoing out:{"species":"Please select a species!"} I double checked the response from the php and firebug shows the same. On success alert is not alerting the JSON data instead, I'm receiving [object Object]. Why is that and how do what should I do to fix this?
I'm currently working on MySQL/PHP/JavaScript project using AJAX. I came across some weird abnormality .for some reason alert(textarea2); shows nothing but if I place another alert(textarea2); right after the first one it works, second pop-up contains responseText....also I've tried alert(resp.responseText); it worked fine,
new Ajax.Request("categories-inset.php", { method: 'get', [code]....
function unHide (fieldname) { .... not important... document.form1.fieldname.style.visibility = 'visible'
}
I have a field name called country in a form. When the onclick="unHide('country')" is used then the above function does not work but if i change the following line within the function document.form1.country.style.visibility = 'visible' then it works.
i wrote a very simple HTML page to test some DOM features between Mozilla and IE. Mozilla is perfect everything went fine and i got the childNodes from my custom tag ( this tag i named <blah> ), inside this tag there is two <span>, that i retrieved. But with IE i really could figure out how its done! Code:
I try to associate DOM nodes with other objects. Assigning custom properties to DOM nodes works in Firefox and Safari. It also works with HTML nodes in IE6. However, it appears not to work with XML nodes that are part of trees returned by XMLHttpRequest. How can I work around this limitation? For XML nodes, I need to be able to associate at most one object with each node.
The syntax I am using is node.customproperty = value
I have a custom HTML tag: <custom>text is here</custom>
I can do anything I would like in terms of calling methods with mozilla but not IE 6. For instance calling appendChild in IE results in an error. The innerHTML property is blank even though there is text between the tag.
Is there a work around for IE. What gives with IE and being able to access and manipulate custom tags??
I would like to include extra "hidden" information in a generated HTML page that can be used by javascript functions.
I realise that most browsers seem to ignore any tags and attributes they don't understand, but from what I can tell the standards do not allow me to make up my own tags or attributes as they will fail validation.
is there any standard element name that can be used for such a purpose i.e. passes validation but never produces any output (and ideally allows nested elements to be rendered normally too)...
I want to have a custom button change appearance when pressed and then call a function and change back to its original appearance when released.
here's what i have now, which works mostly. "drop" is my handler for the button, its argument tells me which button was pressed. i have a number of these buttons and they are organized in a table.
there is a fair amount of superstition here, the result of many tiny experiments i ended up with this which seems to work best: Code:
Does anyone know of a way to wrap custom tags around selected text using execCommand or otherwise?
I am developing a rich text editor for use in a web site and while there are a few decent ones already floating around I need to implement a few extra bits of functionality. Specifically tool tips. Idealy I'd like to wrap custom tags around selected text using execCommand. Ie "Selected Text" becomes:
I would like to use input type file, but i would like to put any file in it when i go on the page for example when user go back after try to submit
imagine any form to fill for send information...but after the user validate....one on the fields is bad...then the user must be correct this field.....But i don't want another fields are empty. The user must just correct one fields and keep another fields
I'm using the jquery in place editor, and I need to get the value of a custom attribute in order to send it with the form. The jquery I have is as folder... (the bit I'm having trouble with is highlighted) $(".edit").editInPlace({ url: "./server.php", params: "folder=" + $(this).attr('folder') //show_buttons: true //$('.edit').attr('folder') });
And the html is as follows: <span class="edit" folder="folderName">text to edit</span> As you can see, I need to get jquery to get the attribute 'folder' value, in this case the value returned would be 'folderName'.
I was reading about delay() in the API ref and it mentioned it used the standard effects queue or a custom queue, but didn't illustrate how you set up a custom queue.
[URL]. It works awesome in all browsers but IE 7 & 8. The custom "alert" is actually a dialog box, with a background fader underneath it, kind of like lightbox. Why IE doesn't play nice?
I've seen several websites using a custom image as a map with google maps controls.I'm familiar with how to use the google maps api in general, but I don't know how to use a custom map image that isn't based on the real world, in other words it will be an image of a map from a video game, so general latitude and longitude wont apply.
Does anyone have a script for a scroller that scrolls a normal page in an iframe when you rollover an image (which would not be inside the iframe rather on the page the iframe is on)?
I've been searching the net for like hours and all I've found have been news tickers and marquees.
Well Im having some problems with a script that I got (prewritten). I altered some parts HTML wise so it works better for me, but I didnt change ANY of the JavaScript at all! But Im getting an object expected error(line 76). I dont know JavaScript at all, so if someone could kindly tell me what I need to change where so that this works. Code: