Forums / Suggestions / Javascript For Datatypes In <head>

Javascript For Datatypes In <head>

Author Message

Douglas Hammond

Monday 23 June 2003 8:11:13 am

There are many cases where one would like to include a js lib in the <head></head> of the document and have it only there if the datatype that uses it, is being used. Plus for adding code to a function that is done for <body onload="function">.

It would be nice if there was a stantdard way to do this.

or can one inject this somehow by refering to the head {section}

Gabriel Ambuehl

Monday 23 June 2003 1:05:17 pm

I duly second this request.

Visit http://triligon.org

Bruce Morrison

Monday 23 June 2003 3:49:46 pm

How about something like

<head>
<script language="JavaScript" src={concat("script/class_",$DesignKeys:used.class,".js")|ezdesign} type="text/JavaScript"></script>
</head>

And you would need to have a javascript file for each class id.

Cheers
Bruce
designIT

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Sven Ryen

Monday 23 June 2003 11:55:50 pm

FWIW, scripts tag can be included anywhere on the page, not just within head tags. I include the javascript src tag at the top of the edit.tpl files of my datatypes.

For onload, how about this snippet:

<script type="text/javascript" language="Javascript">
<!--
document.body.onload = function() { alert('hello world'); }
//-->
</script>

Sven Ryen

Tuesday 24 June 2003 12:12:03 am

As for your request to _append_ to the onload function, this code, although weird, will do the trick:

<script type="text/javascript" language="Javascript">
<!--
onloadtext = "alert('1');";
//-->
</script>

<script type="text/javascript" language="Javascript">
<!--
onloadtext += "alert('2');";
//-->
</script>

<script type="text/javascript" language="Javascript">
<!--
eval("document.body.onload = function() { "+onloadtext+" }");
//-->
</script>