(Answer) (Category) Products of Aardvarks With Chisels : (Category) HTML : (Category) Javascript : (Category) confirm.js :
confirm_flexible.js
The newer, more flexible version. I didn't finish the local:// URL support, but that should be pretty trivial. I just didn't need it. Someday...
demo - http://www.cloudmaster.com/~sauer/demos/confirm_flexible.html
source - http://www.cloudmaster.com/~sauer/demos/confirm_flexible.js
// JavaScript functions to replace "confirm" with an arbitrary
// web page
//
// usage: promptem("message")
//            display message box with the preformatted message included.
//        promptem("http://site.com/page.htm")
//            display message box with the remote URL included
//        promptem("local://path/to/page.htm")
//            display message box with the relative URL included
//
//        promptem("arg1", "height", "width")
//            specify a height and width after the first argument optionally

// you can change these defaults
var title = "Confirmation";
var h = 200;    // default height
var w = 250;    // default width

// you can change the "false"s to "true"s and vice-versa if need be.
function setParams(){
        var p = "";
        p += "toolbar=false";
        p += ",location=false";
        p += ",directories=false";
        p += ",status=false";
        p += ",menubar=false";
        p += ",scrollbars=false";
        p += ",resizable=false";
        p += ",copyhistory=false";
        return(p);
}

/******************************************************************************/
// don't screw with stuff after this line
/******************************************************************************/
var returned = false;
var retVal = false;
var out;
var i=0;

function promptem(){
        window.name = "lenny";
        var text = arguments[0];
        var params = setParams();
        if(arguments.length > 1){
                h = arguments[1];
                w = arguments[2];
        }
        params += ",height=" + h + ",width=" + w;
        out = window.open('', 'out', params);
        out.document.close();
        writeWindow(out);
        writeContent(text, out.frames['content']);
        writeConfirm(out.frames['bottom']);
        out.focus();
        returned = false;
        while(! returned){
                setTimeout(waitForClick, 50);
        }
        alert(i);
        waitForClick();
        return(retVal);
}

// bah.
function waitForClick(){
        i++;
//      alert(i);
//      if(! returned){
//              setTimeout(waitForClick, 50);
//      }
}

// generates the frameset
function writeWindow(win){
        win.document.open();
        win.document.writeln("<HTML><HEAD><TITLE>" + title + "</TITLE></HEAD>");
        with(win.document){
                write("<FRAMESET ROWS='75%,*' BORDER='0'");
                        writeln(" FRAMESPACING='0' FRAMEBORDERS='no'>");
                writeln("<FRAME SRC='' NAME='content' NORESIZE SCROLLING='no'>");
                writeln("<FRAME SRC='' NAME='bottom' NORESIZE SCROLLING='no'>");
                writeln("</FRAMESET></HTML>");
                close();
        }
}

// puts the content into the content frame
function writeContent(text, win){
        colonAt = text.indexOf("://");
        spaceAt = text.indexOf(" ");
        url = false;
        if(colonAt != -1 && (spaceAt == -1 || spaceAt > colonAt)){
                url = true;
        }
        if(url){
                win.location.assign(text);
        }else{
                with(win.document){
                        close();
                        open();
                        writeln("<HTML><BODY>");
                        writeln(substitute(text,"\n","<BR>\n"));
                        writeln("</BODY></HTML>");
                        close();
                }
        }
}

// puts the buttons into the bottom frame
function writeConfirm(win){
        with(win.document){
                close();
                open();
                writeln("<HTML><BODY><FORM><P ALIGN='CENTER'><CENTER>");
                writeln("<INPUT TYPE='BUTTON' NAME='b1' VALUE='OK' onClick='top.opener.butt1();'>");
                writeln("<INPUT TYPE='BUTTON' NAME='b2' VALUE='CANCEL' onClick='top.opener.butt2();'>");
                writeln("</CENTER></P></FORM></BODY></HTML>");
                close();
        }
}

// OK button click handler
function butt1(){
        retVal = true;
        returned = true;
        out.window.close();
}

// Cancel button click handler
function butt2(){
        retVal = false;
        returned = true;
        out.window.close();
}

// replaces  all instances of needle in haystack with newNeedle
function substitute(haystack, needle, newNeedle){
        var end = 0;
        var start = haystack.indexOf(needle, end);
        while(start != -1){
                end = start + needle.length;
                newHaystack = haystack.substring(0, start);
                newHaystack += newNeedle;
                newHaystack += haystack.substring(end, haystack.length);
                end = start + newNeedle.length;
                haystack = newHaystack;
                start = haystack.indexOf(needle, end);
        }
        return haystack;
}
[Append to This Answer]
2001-Nov-26 3:06pm
Previous: (Answer) confirm.js
This document is: http://www.cloudmaster.com/~sauer/projects/index.cgi?file=112
[Search] [Appearance]
This is a Faq-O-Matic 2.719.
This FAQ administered by sauer@cloudmaster.com