我有两个 javascript 函数,只要我将它们保存在我的 head 标签的 HTML 中,它们就可以正常工作,但我想将它们移动到外部 javascript 文件中。
function uploadImageSB() {
Shadowbox.init({});
// shadowbox for image upload
Shadowbox.open({
content: 'photo.cgi?function=photo_upload',
player: 'iframe',
title: 'Image Upload',
height: 200,
width: 500,
options: {
onFinish: function () {
// get the iframe
var iframe = document.getElementById('sb-player');
var formName = 'photoForm';
// add an event listener to determine when the sb form is fully loaded
if (iframe.addEventListener) {
// use addEventListener for Safari, Chrome, Firefox
iframe.addEventListener("load", getTA(formName), true);
} else {
// use attachEvent for IE
iframe.attachEvent("onload", getTA(formName));
}
}
}
})
};
上面的 javascript 调用了下一个函数:
function getTA(fn) {
// get the contents of the tinymce editor
var ed = tinymce.activeEditor;
var content = ed.save();
// dynamically create textarea
var ta = document.createElement('textarea');
ta.textContent = content;
ta.name = 'article';
ta.value = ta.textContent;
// get the iframe content
var iframeContent = this.contentDocument || this.contentWindow.document;
// append the textarea to the shadowbox form, but do not display it
var form = iframeContent.getElementById(fn);
form.appendChild(ta);
form.getElementsByTagName('textarea')[0].style.display = 'none';
};
我认为问题在于我对this
这里的使用:
var iframeContent = this.contentDocument || this.contentWindow.document;
但我不确定如何修复它。谢谢。