So I have an input box ( Name)
Then I have a category drop down box.
Then I have a text area (iframe)
Below that I have a virtual keyboard created; when I click on button it appears in iframe.
So as I said, it works in IE but not in Safari and I would like to know how to save iframe contents into a file.
CSS:
openPage.css
body
{
font-size: 15px;
font-weight: normal;
font-family: calibri;
background-color:black;
color:yellow;
}
.style1 {
margin-top: 11px;
margin-left: 11px;
}
#iTextArea {
width:200px;
height:200px;
background-color:white;
border:thick;
border-color:black;
border-bottom-color:gray;
overflow:auto;
text-wrap:break-word;
font-family:Arial, Helvetica, sans-serif;
color:black;
display:inline;
}
#dToolBar{
width:220px;
height:100px;
}
#dToolBar input{
width:20px;
}
**********************************************
<html>
<head>
<title> New note page </title>
<link rel="stylesheet" href="openPage.css" type="text/css" >
<script type="text/javascript">
initialized = false;
function Init()
{
iTextArea.document.designMode = 'On';
// var dDiv= this.document.getElementById("iTextArea");
// dDiv.contentEditable = true;
createKeyboard();
}
//var frmvalidator = new Validator("myForm");
//frmvalidator.addValidation("Name","maxlen=20","Max length for Name is 20");
function keyValue(val)
{
if(!initialized)
{
tFrame = document.getElementById("iTextArea");
if(tFrame.contentDocument)
{
// Firefox, Opera
doc = tFrame.contentDocument;
}
else if(tFrame.contentWindow)
{
// Internet Explorer
doc = tFrame.contentWindow.document;
}
else if(tFrame.document)
{
// Others?
doc = tFrame.document;
}
doc.open();
initialized = true;
}
doc.write(val);
if(!initialized)
{
doc.close();
}
}
function boldTxt()
{
iTextArea.document.execCommand('bold', false, null);
}
function italicTxt()
{
iTextArea.document.execCommand('italic', false, null);
}
function underlineTxt()
{
iTextArea.document.execCommand('underline', false, null);
}
function insertUnorderedList()
{
iTextArea.document.execCommand('insertunorderedlist', false, null);
}
function insertOrderedList()
{
iTextArea.document.execCommand('insertorderedlist', false, null);
}
function justifyFull()
{
iTextArea.document.execCommand('justifyfull', false, null);
}
function txtFont(txtFont)
{
if(txtFont !='')
iTextArea.document.execCommand('fontname', false, txtFont);
}
function txtSize(txtSize)
{
if(txtSize !='')
iTextArea.document.execCommand('fontsize', false, txtSize);
}
function cancelButton()
{
onclick="history.go(-1)";
}
KB = [ // US Standard Keyboard
[["`", "~"], ["1", "!"], ["2", "@"], ["3", "#"], ["4", "$"], ["5", "%"], ["6", "^"], ["7", "&"], ["8", "*"], ["9", "("], ["0", ")"], ["-", "_"], ["=", "+"], ["Bksp", "Bksp"]],
[["Tab", "Tab"], ["q", "Q"], ["w", "W"], ["e", "E"], ["r", "R"], ["t", "T"], ["y", "Y"], ["u", "U"], ["i", "I"], ["o", "O"], ["p", "P"], ["[", "{"], ["]", "}"], ["\\", "|"]],
[["Caps", "Caps"], ["a", "A"], ["s", "S"], ["d", "D"], ["f", "F"], ["g", "G"], ["h", "H"], ["j", "J"], ["k", "K"], ["l", "L"], [";", ":"], ["'", '"'], ["Enter", "Enter"]],
[["Shift", "Shift"], ["z", "Z"], ["x", "X"], ["c", "C"], ["v", "V"], ["b", "B"], ["n", "N"], ["m", "M"], [",", "<"], [".", ">"], ["/", "?"], ["Styles", "Styles"]],
[[" ", " "]]
];
//font = [ // US Standard Keyboard
// ["B", "makeBold()"],
function createKeyboard()
{
// create an array
//create a div.. min max for kb or
// creata a div inside html and insert all buttons to it
// <input type="button" onClick="typeM(this.value)" value="q">
var prependButtonStr = "<input type='button' onClick='keyValue(this.value)' value='";
var appendButtonStr = "'/>";
// bold.// shift/// caps// font
var buttonStr ="" ;//= prependButtonStr + KB[0][4][1] + appendButtonStr;
// alert(buttonStr);
KB0 =KB[0];
for(i=0; i<KB.length; i++)
{
for(j=0; j<KB.length; j++)
{
buttonStr += prependButtonStr + KB[j][0] + appendButtonStr;
}
}
var dDiv= this.document.getElementById("dToolBar");
dDiv.innerHTML += buttonStr;
// alert(buttonStr.value);
// iTextArea.document.write(buttonStr.value);
}
function toggleDisplay(id, divID, msg){
var dDiv= this.document.getElementById("iTextArea");
if (divID.style.display != "none")
{
divID.style.display="none";
id.value="Keyboard";
dDiv.style.height="300px";
}
else
{
divID.style.display="block";
id.value="Preview";
dDiv.style.height="200px";
}
}
function WriteToFile()
{
var str ="";
str = "<category>" + document.getElementById("Category ").value + "<category>";
str += "<name>" + document.getElementById("name").value + "<name>";
// str += " "+ document.getElementById("iTextArea").innerHTML;
alert(str);
//document.execCommand("SaveAs",false,str);
document.execCommand("SaveAs");
/*
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("c:\\Test.txt", true);
fh.WriteLine("Some text goes here...");
fh.Close();
// after saving go back the previous screen
*/ history.go(-1);
}
// works only in IE..
function m()
{
iTextArea.document.write("m");
}
function OpenFile() {
document.getElementById('iTextArea').src= 'file:///' + document.newNote.fileBrowse.value;
//window.location= 'file:///' + document.newNote.fileBrowse.value;
}
</script>
</head>
<body onLoad="Init()">
<form id="newNote" action="" name="myForm" method="get">
<div class="cHeading" id="dHeading" >
<img id ="dBack"src="Images/CancelButton.jpg" onclick="history.go(-1)" />
<B><span id="dTitle" align="center" > iNOTE App </span></B>
<img id="dTitleIcon" src="Images/NotesIcon.png" alt="App Icon" width="20" height="20" />
<img id="dDone"src=Images/DoneButton.jpg onclick="WriteToFile()" />
</div>
<div id="dContent">
<div id="dFileInfo" >
CATEGORY : <select id="Category " style="width: 117px" >
<option>Category</option>
<option value="Meetings">Meetings</option>
<option value="Grocery">Grocery</option>
<option value="Travel">Travel</option>
<option value="Car">Car</option>
<option value="Other">Other</option>
</select>
<!--img id="dFolderIcon" src="Images/NotesIcon.png" alt="App Icon" width="20" height="20" />
<input id="category"type ="text" name="text" value="" onfocusout="" class="keyboardInput">
<img id="dFolderIcon" src="Images/NotesIcon.png" alt="App Icon" width="20" height="20" /--> </br>
NAME :
<input id ="name"type ="text" name="text" value="" class="keyboardInput" style="width: 134px"></br>
<input id="Preview" type='button' onClick='toggleDisplay(this, dToolBar, "Show Keyboard")' value='Preview'></br>
<input type="button" value="M" onclick="m()">
</div>
<div>
<input type=file name="fileBrowse">
<input type=button onClick="OpenFile()" value="Open File">
</div>
<iframe id="iTextArea" >
</iframe >
</div>
<div id="dToolBar" >
</div>
</form>
</body>
</html>