#### Topic: Access <head> tag and add html

Hi,

I give up, went through all the examples, but I still canot figure it out how can I add one script into head tag.

Starting like this:

tinyMCE.activeEditor.selection.setContent(tinyMCE.activeEditor.dom.createHTML('script', {type : "text/javascript", src : "some_url"},""));

It doesnt work.

What is even more interesting: just alerting head_node variable after first line returns me some giberish not visible in editor->source code..

Any quick help?

#### Re: Access <head> tag and add html

Why not this?

editor.dom.add(
// node(s)
// tag name
"script",
// attributes and their values
{
src: "some_url",
type: "text/javascript"
}
);

I haven't tested this though...

Greetings from Germany,

Felix Riesterer.
-- I am neither Moxiecode nor Ephox! --

#### Re: Access <head> tag and add html

Wau, if this actually works, I'm gonna bite my ass off on monday!!

Will test when I get back to that computer on monday and will let you know.

Thanks for now.

#### Re: Access <head> tag and add html

Hi,

bad news: this doesnt work. I knew it was too easy:D

Anyway, when I add your code into tinymce.PluginManager.add('xxx', function(editor, url) {} into onclick action of addButton function, nothing happens.

Any idea what else could go wrong?

#### Re: Access <head> tag and add html

Can you create a fiddle to showcase your problem?

As for the script I've given you, editor.dom.select() returns a collection (like an array). You would need to take the first element of it:

editor.dom.add(
// node(s)
editor.dom.select("head")[0], // first element
// tag name
"script",
// attributes and their values
{
src: "some_url",
type: "text/javascript"
}
);

I've created a fiddle on my own - check it out!

Greetings from Germany,

Felix Riesterer.
-- I am neither Moxiecode nor Ephox! --

#### Re: Access <head> tag and add html

Nope, even your fiddle doesnt work for me..

I arranged it a bit, does this work for you?
http://fiddle.tinymce.com/y4eaab/2

#### Re: Access <head> tag and add html

subjectx wrote:

Nope, even your fiddle doesnt work for me..

You mean, just because the code editor dialog doesn't show the script element even though it's in the DOM? I've checked using Firebug: It's there!

Maybe some cleanup logic removes it onsubmit and when the code editor displays the supposed "code"?

Greetings from Germany,

Felix Riesterer.
-- I am neither Moxiecode nor Ephox! --

#### Re: Access <head> tag and add html

Hmm, not sure about this logic, but my script doesnt work if I do it your way.

Currently I have stuff put into script tags into body, which is ugly..

Will try to fiddle with your solution, but I doubt it will work, since when I do that with body tag it works and it shows, nothing shows with head tag.

Also like I mentioned earlier, with head tag (showing in code viewer or not) my script doesnt want to work, like its not there..

cant give you direct example, because stuff is across few files and its intern thing, no access from outside to this functions..

Last edited by subjectx (2014-11-25 10:42:10)

#### Re: Access <head> tag and add html

There is a serious issue with the principle of WYSIWYG and your content with embedded JavaScripts on a page! I'm not sure in what way your scripts alter the document contents and if this still has anything to do with WYSIWYG...

Greetings from Germany,

Felix Riesterer.
-- I am neither Moxiecode nor Ephox! --

#### Re: Access <head> tag and add html

I'm trying to implement MathJax functionality, but for text to be transformed from LaTeX form into MATH form, script needs to be called and then script replaces stuff there directly in HTML.

But as I already mentioned: editor is part of a bigger thing and when user finishes with whatever equations needs to be included, we only take whats in editors main window and show that to user as preview. But for equations to be correctly shown, MathJax script has to be included in page, prefferably in head tags...