Right, prince-script() functions cannot update the DOM. Or they can, but it's too late, and it won't affect the document typesetting which is already ongoing. What is it you want to do? There may be another way to do it.
Yup, there might be another way. I even think I saw it here in the forum weeks ago, but I cannot find it anymore.
My Problem: - front matter pages are displayed roman, from say I to IX - for the main matter the page counter is reset to 1 (say 1 to 99), - for the back matter I have to resume the front matter counter, starting with X in this example.
Thus, I need to save the value of the front matter page counter somewhere. (I have tried things like "counter-reset: oldpage counter(page)". Since this didn't work I tried the Javascript approach above.)
Tricky! You could use JavaScript to capture the last page of the front matter and the last page of the main matter, then do the subtraction for the back matter, like this:
I'm not super proud of this solution, though. Also it is tricky to get the Roman numerals in this approach, unless you implement it yourself in JavaScript, which is a little tedious.
Edit: also because we are not actually changing the page counter, cross-references into the back matter will not be correct unless you also use prince-script() for them too.
What about a feature request to allow prince-script() in the counter-reset-property? Then, the old counter could be saved via one prince-script() call, and resumed by a second.