PDA

View Full Version : body onload inside write statement


leviathan
02-21-2006, 06:22 AM
Hi.
I just wanna ask something about this script :

<HTML>
<HEAD>
<TITLE>Redirecting</TITLE>
<SCRIPT LANGUAGE="Javascript">
function starting()
{
window.opener=self;
window.close();
var theWindow = window.open("", "", "menubar=no,resize=no,toolbar=no,scrollbars=yes,status=no,width=800,height=600").document;
theWindow.open("text/html", "replace");
theWindow.clear();
theWindow.write("<html>\n<head><title>Notes</title>");
theWindow.write("<scr"+"ipt language=\"Javascript\">\n");
theWindow.write("function starting(){\n");
theWindow.write("alert(\"TESTER\");\n");
theWindow.write("try\n");
theWindow.write("{alert('ABC');\n");
theWindow.write("}\n");
theWindow.write("catch (e) {\n");
theWindow.write("alert(\"Error.\");\n");
theWindow.write("}\n");
theWindow.write("}");
theWindow.write("</scr"+"ipt></head>\n");
theWindow.write("<body style=\"overflow-x:hidden;overflow-y:scroll;\" onLoad=\"javascript:starting();\">\n");
}
</SCRIPT>
</HEAD>
<BODY onLoad="javascript:starting();">
REDIRECTING
</BODY>
</HTML>

why does the function starting can't work ?

medigerati
02-23-2006, 03:02 AM
function starting()
{
window.opener=self;
window.close();
var theWindow = window.open("", "", "menubar=no,resize=no,toolbar=no,scrollbars=yes,status=no,width=800,height=800").document;

1. You can't close a window you didn't open. Even if this were allowed, it's not very user friendly at all, which is why it isn't allowed.
2. Adding .document to the end of window.open is seems to break the code.

leviathan
03-10-2006, 04:31 AM
to be truth, I want to create a Rich Text Editor under one condition. If we press CTRL+N in the iframe, the only thing that will appear is a blank page. Here is my code :
====================
<HTML>
<HEAD>
<TITLE>Redirecting</TITLE>
<SCRIPT LANGUAGE="Javascript">
function starting()
{
window.opener=self;
window.close();
var theWindow = window.open("", "", "menubar=no,resize=no,toolbar=no,scrollbars=yes,status=no,width=800,height=600").document;
theWindow.open("text/html", "replace");
theWindow.clear();
theWindow.write("<html>\n<head><title>Notes</title>");
theWindow.write("<scr"+"ipt language=\"Javascript\">\n");
theWindow.write("function starting(){\n");
theWindow.write("alert(\"TESTER\");\n");
theWindow.write("try\n");
theWindow.write("{\n");
theWindow.write("document.getElementById(\"edit\").contentWindow.document.designMode = \"On\";\n");
theWindow.write("document.getElementById(\"edit\").contentWindow.document.execCommand(\"fontname\",false,\"Times New Roman\");\n");
theWindow.write("document.getElementById(\"edit\").contentWindow.focus();\n");
theWindow.write("}\n");
theWindow.write("catch (e) {\n");
theWindow.write("alert(\"Aplikasi ini tidak didukung oleh browser anda.\");\n");
theWindow.write("}\n");
theWindow.write("}");

theWindow.write("function changing(changeType)\n");
theWindow.write("{\n");
theWindow.write("document.getElementById(\"edit\").contentWindow.focus();\n");
theWindow.write("document.getElementById(\"edit\").contentWindow.document.execCommand(changeType, false, null);\n");
theWindow.write("document.getElementById(\"edit\").contentWindow.focus();\n");
theWindow.write("}\n");


theWindow.write("</scr"+"ipt></head>\n");
theWindow.write("<body style=\"overflow-x:hidden;overflow-y:scroll;\" onLoad=\"javascript:starting();\">\n");
theWindow.write("<form><table border=\"0\" width=\"90%\" align=\"center\">\n");
theWindow.write("<tr>\n");
theWindow.write(" <td align=\"center\">\n");
theWindow.write(" <input type=\"button\" id=\"bold\" value=\"B\" onClick=\"changing(this.id)\">\n");
theWindow.write(" <input type=\"button\" id=\"italic\" value=\"I\" onClick=\"changing(this.id)\">\n");
theWindow.write(" <input type=\"button\" id=\"underline\" value=\"U\" onClick=\"changing(this.id)\">\n");
theWindow.write(" &nbsp;&nbsp;&nbsp;\n");
theWindow.write(" <select id=\"fontname\" onChange=\"changeFont(this.id)\">\n");
theWindow.write(" <option selected>--Font Type--</option>\n");
theWindow.write(" <option name=\"Arial\" value=\"Arial\" style=\"background-color:#FFFFFF;font-family:Arial\">Arial</option>\n");
theWindow.write(" <option name=\"Courier\" value=\"Courier\" style=\"background-color:#FFFFFF;font-family:Courier\">Courier</option>\n");
theWindow.write(" <option name=\"Georgia\" value=\"Georgia\" style=\"background-color:#FFFFFF;font-family:Georgia\">Georgia</option>\n");
theWindow.write(" <option name=\"Lucida Console\" value=\"Lucida Console\" style=\"background-color:#FFFFFF;font-family:Lucida Console\">Lucida Console</option>\n");
theWindow.write(" <option name=\"Tahoma\" value=\"Tahoma\" style=\"background-color:#FFFFFF;font-family:Tahoma\">Tahoma</option>\n");
theWindow.write(" <option name=\"Times New Roman\" value=\"Times New Roman\" style=\"background-color:#FFFFFF;font-family:Times New Roman\">Times New Roman</option>\n");
theWindow.write(" <option name=\"Verdana\" value=\"Verdana\" style=\"background-color:#FFFFFF;font-family:Verdana\">Verdana</option>\n");
theWindow.write(" </select>\n");
theWindow.write(" <select id=\"fontsize\" onChange=\"changeFont(this.id)\">\n");
theWindow.write(" <option selected>--Font Size--</option>\n");
theWindow.write(" <option name=\"1\" value=\"1\">8</option>\n");
theWindow.write(" <option name=\"2\" value=\"2\">10</option>\n");
theWindow.write(" <option name=\"3\" value=\"3\">12</option>\n");
theWindow.write(" <option name=\"4\" value=\"4\">14</option>\n");
theWindow.write(" <option name=\"5\" value=\"5\">16</option>\n");
theWindow.write(" <option name=\"6\" value=\"6\">18</option>\n");
theWindow.write(" <option name=\"7\" value=\"7\">24</option>\n");
theWindow.write(" </select>\n");
theWindow.write(" <select id=\"forecolor\" onChange=\"changeFont(this.id)\">\n");
theWindow.write(" <option selected>--Font Color--</option>\n");
theWindow.write(" <option name=\"black\" value=\"#000000\" style=\"background-color:#000000\">Black</option>\n");
theWindow.write(" <option name=\"red\" value=\"#FF0000\" style=\"background-color:#FF0000\">Red</option>\n");
theWindow.write(" <option name=\"yellow\" value=\"#00FF00\" style=\"background-color:#00FF00\">Green</option>\n");
theWindow.write(" <option name=\"green\" value=\"#FFFF00\" style=\"background-color:#FFFF00\">Yellow</option>\n");
theWindow.write(" <option name=\"magenta\" value=\"#00FFFF\" style=\"background-color:#00FFFF\">Magenta</option>\n");
theWindow.write(" <option name=\"blue\" value=\"#0000FF\" style=\"background-color:#0000FF\">Blue</option>\n");
theWindow.write(" <option name=\"purple\" value=\"#FF00FF\" style=\"background-color:#FF00FF\">Purple</option>\n");
theWindow.write(" <option name=\"silver\" value=\"#C0C0C0\" style=\"background-color:#C0C0C0\">Silver</option>\n");
theWindow.write(" <option name=\"white\" value=\"#FFFFFF\" style=\"background-color:#FFFFFF\">White</option>\n");
theWindow.write(" </select>\n");
theWindow.write(" </td>\n");
theWindow.write("</tr>\n");
theWindow.write("<tr>\n");
theWindow.write(" <td align=\"center\">\n");
theWindow.write(" <input type=\"button\" id=\"insertorderedlist\" value=\"Number&nbsp;List\" onClick=\"changing(this.id)\">\n");
theWindow.write(" <input type=\"button\" id=\"insertunorderedlist\" value=\"Bullet&nbsp;List\" onClick=\"changing(this.id)\">\n");
theWindow.write(" &nbsp;&nbsp;&nbsp;\n");
theWindow.write(" <input type=\"button\" id=\"justifyleft\" value=\"Left\" onClick=\"changing(this.id)\">\n");
theWindow.write(" <input type=\"button\" id=\"justifycenter\" value=\"Center\" onClick=\"changing(this.id)\">\n");
theWindow.write(" <input type=\"button\" id=\"justifyright\" value=\"Right\" onClick=\"changing(this.id)\">\n");
theWindow.write(" <input type=\"button\" id=\"justifyfull\" value=\"Justify\" onClick=\"changing(this.id)\">\n");
theWindow.write(" &nbsp;&nbsp;&nbsp;\n");
theWindow.write(" <input type=\"button\" id=\"indent\" value=\"Indent\" onClick=\"changing(this.id)\">\n");
theWindow.write(" <input type=\"button\" id=\"outdent\" value=\"Outdent\" onClick=\"changing(this.id)\">\n");
theWindow.write(" </td>\n");
theWindow.write("</tr>\n");
theWindow.write("<tr>\n");
theWindow.write(" <td align=\"center\">Table :\n");
theWindow.write(" Col(s) <input type=\"text\" id=\"col\" value=\"1\" size=\"5\" onKeyUp=\"javascript:numericVal(this);\" maxlength=\"3\">\n");
theWindow.write(" Row(s) <input type=\"text\" id=\"row\" value=\"1\" size=\"5\" onKeyUp=\"javascript:numericVal(this);\" maxlength=\"3\">\n");
theWindow.write(" <input type=\"button\" id=\"create_table\" value=\"Create&nbsp;Table\" onClick=\"javascript:addTable();\">\n");
theWindow.write(" </td>\n");
theWindow.write("</tr>\n");
theWindow.write("<tr>\n");
theWindow.write(" <td align=\"center\">\n");
theWindow.write(" <input type=\"button\" value=\"Preview\" onClick=\"preview()\">\n");
theWindow.write(" <br><br><br>\n");
theWindow.write(" <iframe id=\"edit\" width=\"720\" height=\"500px\" scrolling=\"auto\"></iframe>\n");
theWindow.write(" </td>\n");
theWindow.write("</tr>\n");
theWindow.write("</table>\n");
theWindow.write("</form>");
theWindow.write("</body></html>");
theWindow.refresh();

}
</SCRIPT>
</HEAD>
<BODY onLoad="javascript:starting();">
REDIRECTING
</BODY>
</HTML>
=========

the question is in this part :
theWindow.write("<body style=\"overflow-x:hidden;overflow-y:scroll;\" onLoad=\"javascript:starting();\">\n");

it supposed to run the starting function, right ? but, the only problem is, it don't. why ? can anyone help me ?

leviathan
03-10-2006, 08:28 AM
ah, well.
I'll just ask. When I activate the design mode in an iframe, can the "Ctrl+N" function be disabled ? Well, I can't :( :( :(