Forum How do I...?

How do I call external Javascript to my Html Before Conversion in C#

mohammad
Hi,

I am trying to call javascript function from auto generated content same as the sample.

I have this css file
@page {
    @top {
	content: prince-script(datestamp)
    }
}

p{
 color :red;
}


I have this javascript file

function datestamp()
{
    return (new Date()).toString();
}


I have this html

<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
</title>
</head>
<body>
 
<p id='a'>hello</p>
<script>
documnet.getElementByid('a').style.color = 'black';  \\ this not working
</script>

</body>
</html>


but neither my top of the page has the datetime or my paragraph colored in black

My input is

hello in red


I have this c# code as well

prn.AddScript("C:\\PrinceXML\\Prince.js");

prn.AddStyleSheet("C:\\PrinceXML\\Prince.css");

I tried swiping adding CSS before JS but it is not working

The log info is

Mon Jul 8 16:58:38 2013: ---- begin
Mon Jul 8 16:58:38 2013: Loading document...
Mon Jul 8 16:58:38 2013: Running scripts...
Mon Jul 8 16:58:38 2013: Applying style sheets...
Mon Jul 8 16:58:38 2013: Preparing document...
Mon Jul 8 16:58:38 2013: Converting document...
Mon Jul 8 16:58:38 2013: warning: unknown script function "datestamp", register with Prince.addScriptFunc
Mon Jul 8 16:58:38 2013: finished: success
Mon Jul 8 16:58:38 2013: ---- end

Any Help is appreciated.

Thanks/

Edited by mikeday

mikeday
Sorry about this, we haven't updated the documentation for Prince 9 yet. You now need to register script functions before using them, by adding this to your JavaScript:
Prince.addScriptFunc("datestamp", datestamp);

Or you can define the function inline:
Prince.addScriptFunc("datestamp", function() { return (new Date()).toString(); });

Explicitly naming the script functions gives us much more flexibility behind the scenes, and we should have implemented it this way in the first place. :)
mohammad
Thank you for your answer. I was thinking of this, but one of the group members said that using prince-script was available in version 9. I tried this and now it is working.

Thanks a lot.
jerkob
[Earlier posting removed]

Editing to remove as I was mistaken about this. I did not realize that this only pertained to using scripts in CSS. Apologies for my confusion.

Edited by jerkob