OL Learn

getElementById from master page

Hi,
How to change value via JavaScript in Master Page object (print context)? (2018.1)
For instance:
in Master Page I have

<p id="ident">sth</p>

in JS code I have

document.getElementById('ident').innerHtml = 'sth_else';

  • does not make change :frowning:

I don’t want to set it in template script (in Script Panel)
Thank you in advance,

Not sure I get what you want to do. Other than using the Javascript language in the server-side scripts (Scripts panel), you cannot access Master Page from a Javascript file as Javascript file are used with Web Context and the latter don’t have Master Pages.

I thought, if I can use client-side scripts for Context\Print\Template I can also use it for Master Page ‘section’:

example:
I want to print a data&time of printing document (in Master Page ‘section’)
solution:
in Master Page I have

<div id="timestampMP"></div>

in JS (client-side):

document.getElementById('timestampMP').innerHtml = Date.now();

above doesn’t run

But if I have

<div id="timestampFP"></div>

not in Master Page but inside Context\Print\Template
the JS code:

document.getElementById('timestampFP').innerHtml = Date.now();

runs :slight_smile:

My question is how to implement JS client-side Master Page ‘section’, is it possible?

Javascript file are used with Web Context

not quite, documentation says that JS client-side scripts are used with Print Context as well (if I understand well :slight_smile: )

A client-side script requires a client… a printer or a PDF is not considered a “client”, but a browser is.

In any event, you should simply add a script to the Scripts pane:
TimeStamp

By the way, the help file contains some pretty specific information about this:
https://help.objectiflune.com/en/pres-connect-user-guide/2020.1/#designer/Web/Using_JavaScript.htm#toc-5

However, I checked the documentation for 2018.1 and found it did not yet explain that scripts run before the master page is added, so that’s probably what caused the confusion.

Thank you,
Key issue is:

“So it is possible to change Print output (except content on Master Pages) by a JavaScript;”