How to call a javascript function?

How to call a javascript function while openning or exit an IE publication ?

I have tried function OnPubLoaded, It dose not work.

function OnPubLoaded: Boolean;
begin
// When the publication is starting.
// Set Result to True if you want to exit immediately without any warning.
ExecuteHTMLScript(“Say(‘123’)”,“JavaScript”);
Result := false;
end;

Niether procedure OnPubBeingClosed

procedure OnPubBeingClosed;
begin
// When the publication is going to be closed.
ExecuteHTMLScript(“Say(‘123’)”,“JavaScript”);
end;

I got JavaScript Error:
0 1:1
The value of the property ‘Say’ is null or undefined, not a Function object

It’s probably due to the fact that the JavaScript code isn’t loaded into the browser at the time of OnPubLoaded and the other one. Try other UserMain events.