2012-07-03 33 views
0

請幫我解決我的問題。我在我的網站http://bonus.lg.ua上有Sobi2。所有的作品都很完美,但是我將我的瀏覽器從Firefox更改爲Chrome,並且與Sobis的條目Edit Html Sourse的按鈕有問題。當我按下Chrome中的Entry Edit按鈕「Edit Html Sourse」時,打開空的彈出窗口,並帶有複選框和文本「{$ lang_theme_code_wordwrap}」,這就是全部。室內用開發工具,我得到一個錯誤:Uncaught TypeError:無法讀取未定義的屬性'htmlSource'

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> 
+0

任何「無法讀取......未定義」錯誤意味着您正在嘗試查詢的元素未找到。你的情況,'document.forms [0]'。運行'console.log(document.forms)' - 你看到表單被返回嗎?如果你確定表單存在,爲什麼不選擇ID,jQuery選擇器或其他方式? – Utkanos

+0

無表單返回。 console.log(document.forms) - undefined –

+0

然後這就是你的問題 - 表單不存在,或者至少沒有通過你正在使用的選擇過程找到。你確定表單在頁面中嗎?正如我所描述的,嘗試一種不同的選擇方式。 – Utkanos

回答

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> 
相關問題