Skip to main content
Participant
February 21, 2008
Question

Add JavaScript Code to head

  • February 21, 2008
  • 1 reply
  • 1141 views
We use a customized button for submitting forms or links at work. The code combines DHTML elements for the look and functionality of the button. I've created an extension, and it adds the HTML and CSS code, but when I try to add the JavaScript, I get an error because DreamWeaver tries to parse the JavaScript as a part of the extension.

I can't figure out how to get the JavaScript into the <head> of the document like the CSS. I've looked at numerous functions and I just can't find enough documentation to get a full understanding. Any help is greatly appreciated.
This topic has been closed for replies.

1 reply

Inspiring
February 21, 2008
figmentthinking wrote:
> We use a customized button for submitting forms or links at work. The code
> combines DHTML elements for the look and functionality of the button. I've
> created an extension, and it adds the HTML and CSS code, but when I try to add
> the JavaScript, I get an error because DreamWeaver tries to parse the
> JavaScript as a part of the extension.
>
> I can't figure out how to get the JavaScript into the <head> of the document
> like the CSS. I've looked at numerous functions and I just can't find enough
> documentation to get a full understanding. Any help is greatly appreciated.
>


You have not given much to go on, but it might be that you did not
realize that any '</script>' tags needed to be masked from DW Extension
API by breaking them up into '</scr'+'ipt>'

--


E. Michael Brandt

www.divahtml.com
www.divahtml.com/products/scripts_dreamweaver_extensions.php
Standards-compliant scripts and Dreamweaver Extensions

www.valleywebdesigns.com/vwd_Vdw.asp
JustSo PictureWindow
JustSo PhotoAlbum, et alia

--
Inspiring
February 22, 2008
You have not said, but I gather you are using the Command API, which is
the most flexible and powerful of the three: Behavior, Object and
Command APIs.

With that API, you can simply add to the innerHTML of the Head (or the
"head" Editable Region of a Child page, or NOT the "head" editable
region of a Template) a string containing your new script, as long as
you break up the </script> tag. To be safe I often break up the opening
<script> tag too.

So, for example:

var str='<scr'+'ipt type="text/javascript"> blah blah</scr'+'ipt>';

var head=dw.getDocumentDOM().getElementsByTagName('HEAD')[0];
head.innerHTML=head.innerHTML+str;

--


E. Michael Brandt

www.divahtml.com
www.divahtml.com/products/scripts_dreamweaver_extensions.php
Standards-compliant scripts and Dreamweaver Extensions

www.valleywebdesigns.com/vwd_Vdw.asp
JustSo PictureWindow
JustSo PhotoAlbum, et alia

--