Google 크롬은 이제 사용자 스크립트 it does not allow any access to the target page's javascript objects에 대해 unsafeWindow
을 정의합니다. DOM에 대한 액세스 만 허용합니다.
는 크로스 브라우저 스크립트를 제공 할 수 해결하려면, 완전한 기능을 갖춘
unsafeWindow
-
this answer와 같이
/*--- Create a proper unsafeWindow object on browsers where it doesn't exist
(Chrome, mainly).
Chrome now defines unsafeWindow, but does not give it the same access to
a page's javascript that a properly unsafe, unsafeWindow has.
This code remedies that.
*/
var bGreasemonkeyServiceDefined = false;
try {
if (typeof Components.interfaces.gmIGreasemonkeyService === "object") {
bGreasemonkeyServiceDefined = true;
}
}
catch (err) {
//Ignore.
}
if (typeof unsafeWindow === "undefined" || ! bGreasemonkeyServiceDefined) {
unsafeWindow = (function() {
var dummyElem = document.createElement('p');
dummyElem.setAttribute ('onclick', 'return window;');
return dummyElem.onclick();
})();
}
OR, 당신이 사용하는 스크립트를 리팩토링 수 있습니다 스크립트 삽입 ...
function main() {
//--- PUT EVERYTHING IN THIS WRAPPER FUNCTION...
var tm = tinyMCE;
if (tm!= null) {
var _tempcontent = tm.activeEditor.getContent();
console.log(_tempcontent);
}
}
addJS_Node (null, null, main);
function addJS_Node (text, s_URL, funcToRun) {
var D = document;
var scriptNode = D.createElement ('script');
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
//--- Don't error check here. if DOM not available, should throw error.
targ.appendChild (scriptNode);
}
무엇이 정의되지 않습니까? 변수 tm? var tinymce를 확인할 수 있습니까? 너는 무엇을 얻 느냐? – Thariama
예, unsafeWindow.tinyMCE가 아니기 때문에 변수 tm이 정의되지 않았습니다. – Openmindeo