未捕获的TypeError:无法读取未定义的属性'htmlSource'

时间:2012-07-03 09:50:55

标签: javascript javascript-events

请帮我解决我的问题。我的网站http://bonus.lg.ua上有Sobi2。一切都很完美,但我将我的浏览器从Firefox改为Chrome,并且在Sobis的条目Edit Html Sourse按钮上有问题。当我按下Chrome中的“编辑Html Sourse”条目按钮时,打开空白弹出窗口,其中包含复选框和文本“{$ lang_theme_code_wordwrap}”,这就是全部。开发人员工具我得到下一个错误:

Uncaught TypeError: Cannot read property 'htmlSource' of undefined source_editor.js:18

这里是sourse_editor.js,函数“函数onLoadInit()”中的错误:

function saveContent() {
    tinyMCE.setContent(document.getElementById('htmlSource').value);
    tinyMCE.closeWindow(window);
}

// Fixes some charcode issues
function fixContent(html) {
/*  html = html.replace(new RegExp('<(p|hr|table|tr|td|ol|ul|object|embed|li|blockquote)', 'gi'),'\n<$1');
    html = html.replace(new RegExp('<\/(p|ol|ul|li|table|tr|td|blockquote|object)>', 'gi'),'</$1>\n');
    html = tinyMCE.regexpReplace(html, '<br />','<br />\n','gi');
    html = tinyMCE.regexpReplace(html, '\n\n','\n','gi');*/
    return html;
}

function onLoadInit() {
    tinyMCEPopup.resizeToInnerSize();

    document.forms[0].htmlSource.value = fixContent(tinyMCE.getContent(tinyMCE.getWindowArg('editor_id')));
    resizeInputs();
}

function setWrap(val) {
    var s = document.forms[0].htmlSource;

    s.wrap = val;

    if (tinyMCE.isGecko) {
        var v = s.value;
        var n = s.cloneNode(false);
        n.setAttribute("wrap", val);
        s.parentNode.replaceChild(n, s);
        n.value = v;
    }
}

function toggleWordWrap(elm) {
    if (elm.checked)
        setWrap('soft');
    else
        setWrap('off');
}

var wHeight=0, wWidth=0, owHeight=0, owWidth=0;

function resizeInputs() {
    if (!tinyMCE.isMSIE) {
         wHeight = self.innerHeight-80;
         wWidth = self.innerWidth-16;
    } else {
         wHeight = document.body.clientHeight - 80;
         wWidth = document.body.clientWidth - 16;
    }

    document.forms[0].htmlSource.style.height = Math.abs(wHeight) + 'px';
    document.forms[0].htmlSource.style.width  = Math.abs(wWidth) + 'px';
}

function renderWordWrap() {
    if (tinyMCE.isMSIE || tinyMCE.isGecko)
        document.write('<input type="checkbox" name="wraped" id="wraped" onclick="toggleWordWrap(this);" class="wordWrapCode" /><label for="wraped">{$lang_theme_code_wordwrap}</label>');
}

这是“source_editor.htm”:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>{$lang_theme_code_title}</title>
<script language="javascript" type="text/javascript"
    src="../../tiny_mce_popup.js"></script>
<script language="javascript" type="text/javascript"
    src="jscripts/source_editor.js"></script>
<base target="_self" />
</head>
<body onload="tinyMCEPopup.executeOnLoad('onLoadInit();');"
    onresize="resizeInputs();" style="display: none">
<form name="source" onsubmit="saveContent();" action="#">
<div style="float: left" class="title">{$lang_theme_code_title}</div>

<div style="float: right"><script language="javascript"
    type="text/javascript">renderWordWrap();</script></div>

<textarea name="htmlSource" id="htmlSource" rows="15" cols="100"
    style="width: 100%; height: 100%; font-family: 'Courier New',Courier,mono; font-size: 12px"
    dir="ltr" wrap="off"></textarea>

<div class="mceActionPanel">
<div style="float: left"><input type="button" name="insert"
    value="{$lang_update}" onclick="saveContent();" id="insert" /></div>

<div style="float: right"><input type="button" name="cancel"
    value="{$lang_cancel}" onclick="tinyMCEPopup.close();" id="cancel" />
</div>
</div>
</form>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

如果只是将textarea包装在表单元素中,那么这个问题就应该解决了:

<form>
  <textarea name="htmlSource" id="htmlSource" rows="15" cols="100"
    style="width: 100%; height: 100%; font-family: 'Courier New',Courier,mono; font-size: 12px"
    dir="ltr" wrap="off"></textarea>
</form>