registerFormat
The registerFormat method registers a special ad format under a name. It
is normally called by a format’s own CDN app (htag-format-<name>) when that app is lazily loaded — you rarely
call it directly.
Syntax
Section titled “Syntax”window.htag.api('1').registerFormat(name, format);Parameters
Section titled “Parameters”name(string): The format’s unique name (lowercase letters, digits and dashes), e.g.'sidebar'.format(object): The format definition.applyFormat(divId)(function, required): Applies the format to the placement elementdivId. Returns an optional teardown function that Htag runs when the ad reloads/refreshes (wired into the Effects system under thead:{divId}tag). Return nothing for a no-op.allowScheduledReload()(function, optional): Returns whether Htag may automatically (timer/scheduled) reload the placement while this format is active. Defaults totrue(reloadable) when omitted.
Example
Section titled “Example”// Inside the htag-format-<name> app, executed on load:const sidebar = { applyFormat(divId) { const teardown = expand(divId); // your DOM work return teardown; // run automatically on the next ad reload }, allowScheduledReload: () => false, // keep the format on screen; suppress auto-reloads};
window.htag.api('1').registerFormat('sidebar', sidebar);Related Methods
Section titled “Related Methods”- bindFormat: Bind a registered format to a placement
- Special Ad Formats: How formats are packaged, loaded and triggered
- saveEffect: The effects mechanism behind a format’s teardown