📄 js.js
字号:
var colour;
var htmlOn;
//Function to format text in the text box
function FormatText(command, option) {
//Colour pallete
if ((command == "forecolor") || (command == "backcolor")) {
parent.command = command;
buttonElement = document.getElementById(command);
document.getElementById("message").contentWindow.focus()
document.getElementById("colourPalette").style.left = getOffsetLeft(buttonElement) + "px";
document.getElementById("colourPalette").style.top = (getOffsetTop(buttonElement) + buttonElement.offsetHeight) + "px";
if (document.getElementById("colourPalette").style.visibility=="hidden")
document.getElementById("colourPalette").style.visibility="visible";
else {
document.getElementById("colourPalette").style.visibility="hidden";
}
//get current selected range
var sel = document.getElementById("message").contentWindow.document.selection;
if (sel != null) {
colour = sel.createRange();
}
}
//Text Format
else {
document.getElementById("message").contentWindow.focus();
document.getElementById("message").contentWindow.document.execCommand(command, false, option);
document.getElementById("message").contentWindow.focus();
}
}
//Function to set colour
function setColor(color) {
//retrieve selected range
var sel = document.getElementById("message").contentWindow.document.selection;
if (sel!=null) {
var newColour = sel.createRange();
newColour = colour;
newColour.select();
}
document.getElementById("message").contentWindow.focus();
document.getElementById("message").contentWindow.document.execCommand(parent.command, false, color);
document.getElementById("message").contentWindow.focus();
document.getElementById("colourPalette").style.visibility="hidden";
}
//Function to add image
function AddImage() {
imagePath = prompt("输入你要插入的图片的地址", "http://www.78798.com/image.gif");
if ((imagePath != null) && (imagePath != "")) {
document.getElementById("message").contentWindow.focus()
document.getElementById("message").contentWindow.document.execCommand("InsertImage", false, imagePath);
}
document.getElementById("message").contentWindow.focus()
}
function AddFlash()
{
retval = window.prompt("输入你要插入的Flash的地址","http://www.78798.com/flash.swf");
if( retval != null ){
document.getElementById("message").contentWindow.focus()
var htmlLink = document.getElementById("message").contentWindow.document.selection.createRange()
//var infoContent="<embed src='"+retval+"' type='application/x-shockwave-flash'></embed>";
var infoContent="<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME=movie VALUE='"+retval+"'><PARAM NAME=quality VALUE=high><embed src='"+retval+"' quality=high pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'>'"+retval+"'</embed></OBJECT>";
htmlLink.pasteHTML(infoContent);
document.getElementById("message").contentWindow.document.execCommand('paste', false,'');
}
document.getElementById("message").contentWindow.focus()
}
function AddReal()
{
retval = window.prompt('输入你要插入的Real的地址','http://www.78798.com/real.rm');
if( retval != null ){
document.getElementById("message").contentWindow.focus()
var htmlLink = document.getElementById("message").contentWindow.document.selection.createRange()
var infoContent="<object id=\"RVOCX\" classid=\"CLSID:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" width=\"320\" height=\"240\">\n";
infoContent=infoContent+"<param name=\"SRC\" value=\""+retval+"\">\n";
infoContent=infoContent+"<param name=\"CONTROLS\" value=\"ImageWindow\">\n";
infoContent=infoContent+"<param name=\"CONSOLE\" value=\"cons\">\n";
infoContent=infoContent+"<embed src=\""+retval+"\" type=\"audio/x-pn-realaudio-plugin\" width=\"320\" height=\"240\" controls=\"ImageWindow\" console=\"cons\"></embed>\n";
infoContent=infoContent+"</object>\n";
htmlLink.pasteHTML(infoContent);
document.getElementById("message").contentWindow.document.execCommand('paste', false,'');
}
document.getElementById("message").contentWindow.focus()
}
function AddWMP()
{
retval = window.prompt('输入你要插入的WMP的地址','http://www.78798.com/media.asf');
if( retval != null ){
document.getElementById("message").contentWindow.focus()
var htmlLink = document.getElementById("message").contentWindow.document.selection.createRange()
var infoContent="<embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src="+retval+" width=320 height=240></embed>\n";
htmlLink.pasteHTML(infoContent);
document.getElementById("message").contentWindow.document.execCommand('paste', false,'');
}
document.getElementById("message").contentWindow.focus()
}
//Function to switch to HTML view
function HTMLview() {
//WYSIWYG view
if (htmlOn == true) {
var html = document.getElementById("message").contentWindow.document.body.innerText;
document.getElementById("message").contentWindow.document.body.innerHTML = html;
document.getElementById("ToolBar1").style.visibility="visible";
document.getElementById("ToolBar2").style.visibility="visible";
htmlOn = false;
//HTML view
} else {
var html = document.getElementById("message").contentWindow.document.body.innerHTML;
document.getElementById("message").contentWindow.document.body.innerText = html;
document.getElementById("ToolBar1").style.visibility="hidden";
document.getElementById("ToolBar2").style.visibility="hidden";
htmlOn = true;
}
}
//Function to clear form
function ResetForm() {
if (window.confirm("您确认要重新填写此表单吗?")) {
document.postForm.reset();
document.getElementById("message").contentWindow.focus()
document.getElementById("message").contentWindow.document.body.innerHTML = "";
return true;
}
return false;
}
//Function to add smiley
function AddSmileyIcon(imagePath){
document.getElementById("message").contentWindow.focus();
document.getElementById("message").contentWindow.document.execCommand("InsertImage", false, imagePath);
}
//Colour pallete top offset
function getOffsetTop(elm) {
var mOffsetTop = elm.offsetTop;
var mOffsetParent = elm.offsetParent;
while(mOffsetParent){
mOffsetTop += mOffsetParent.offsetTop;
mOffsetParent = mOffsetParent.offsetParent;
}
return mOffsetTop;
}
//Colour pallete left offset
function getOffsetLeft(elm) {
var mOffsetLeft = elm.offsetLeft;
var mOffsetParent = elm.offsetParent;
while(mOffsetParent) {
mOffsetLeft += mOffsetParent.offsetLeft;
mOffsetParent = mOffsetParent.offsetParent;
}
return mOffsetLeft;
}
//Function to hide colour pallete
function hideColourPallete() {
document.getElementById("colourPalette").style.visibility="hidden";
}
//Function to perform spell check
function checkspell() {
try {
var tmpis = new ActiveXObject("ieSpell.ieSpellExtension");
tmpis.CheckAllLinkedDocuments(document);
}
catch(exception) {
if(exception.number==-2146827859) {
if (confirm("浏览器自动拼写检查(ieSpell)没有检测到。点击“确定”转到下载页面。"))
openWin("http://www.iespell.com/download.php","DownLoad", "");
}
else
alert("Error Loading ieSpell: Exception " + exception.number);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -