Skip to main content
November 19, 2009
Question

Append css to head (extension writing)

  • November 19, 2009
  • 2 replies
  • 720 views

Hi,

I'm working on an extension that lets users (in the Users Interface) specify a color and then writes it to the css in the head of theire page. I can't however find a dw function in the DW API to write a css style to the head tag.  I know how to link an external file (copy assets) but this time I want to append the css straight to the head tag.

Thanks for any help!

Reg. Peet

This topic has been closed for replies.

2 replies

November 25, 2009

Since no one seems to be able to answer my question I will post the answer I found (was hard to find) here:

function scriptInsert(){

    //the Style Sheet

MyStyle="";
MyStyle+="."+SenderForm.class.value+" {"
MyStyle+="background-Color:"+SenderForm.fontBGColor.value+";"
MyStyle+="}"


thePageDom=dreamweaver.getDocumentDOM("document")
theStyle=thePageDom.getElementsByTagName("STYLE")
theHeadNode=thePageDom.getElementsByTagName("HEAD")
 
// we need a new style tag inside the head
theHeadNode=thePageDom.getElementsByTagName("HEAD")


//create the new style tag and put the styles inside
theHeadNode.item(0).innerHTML = theHeadNode.item(0).innerHTML+"<style type=\"text/css\">"+MyStyle+"</style>";

window.close()
}

I call the function from within the objectTag() function

Hope this helps out other extensionwriters.

The result is an extension that adds a div with rounded corners to the page: http://www.michielvandijk.nl/downloads (free )

November 22, 2009

I found a snippet of javascript that might do the trick as discribed on this

thread: http://forums.adobe.com/message/2408663#2408663

The javascript goes as follows:

var heads = dw.getDocumentDOM().getElementsByTagName("head");
paramObj.head__tag = heads[0];

Apparently it hase to be placed in a function called: applyCommand()  but I don't know why, nor do I know where the varriable that holds my css code that I want to append goes in these lines.

Can anyone explain the javascript, why it must be in that function and where my variable goes?

Thanks for any help!

Peet