Random headers?

Questions about XML that are not covered by the other forums should go here.
OysterMug
Posts: 3
Joined: Sun Mar 12, 2023 9:45 pm

Random headers?

Post by OysterMug »

Is there any way in XML to randomly display a different (Header) image every time a user visits the site?

TIA
Radu
Posts: 9212
Joined: Fri Jul 09, 2004 5:18 pm

Re: Random headers?

Post by Radu »

Hi,

What type of XML documents are you publishing?
For example if you publish DITA XML documents to HTML5 or WebHelp you can set parameters to add small HTML snippets to the headers or footers of the page. And those small HTML snippets can use for example Javascript to make various decisions like displaying adds, images.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
OysterMug
Posts: 3
Joined: Sun Mar 12, 2023 9:45 pm

Re: Random headers?

Post by OysterMug »

Thx for the reply.

I'm creating/editing a theme for a MyBB website. How do I embed a JavaScript call in the XML? (I can probably figure out how to do what I need in JS.)
Can I call a ".js" file instead of embedding the entire script? (It's bound to be lengthy.)
Thx.
Radu
Posts: 9212
Joined: Fri Jul 09, 2004 5:18 pm

Re: Random headers?

Post by Radu »

Hi,

I am not familiar with MyBB XML themes and their features, please try to ask this question on a web site or users support group more oriented towards people who use such themes.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
OysterMug
Posts: 3
Joined: Sun Mar 12, 2023 9:45 pm

Re: Random headers?

Post by OysterMug »

Thx. I posted the question there as well. No response.

You might still be able to help. I need to embed the following JavaScript code in my XML (which then calls it):

Code: Select all

function getRandomHeader() {
  min = Math.ceil(1.0);
  max = Math.floor(8.0);
  var RandVal = Math.floor(Math.random() * (max - min + 1) + 1810);
  const RandomHeader = "<![CDATA[attachment.php?aid=${RandVal}]]>";
  console.log(RandomHeader);
}
...which produces a result such as "<![CDATA[attachment.php?aid=1811]]>"

I need XML to call the function (I believe this is how):
<logo>$:getRandomHeader()</logo>

I just don't know where to put the code. In between "<script>" tags? TIA
Radu
Posts: 9212
Joined: Fri Jul 09, 2004 5:18 pm

Re: Random headers?

Post by Radu »

Hi,

This XML document is some kind of configuration file containing details about a theme, right?
It is consumed and interpreted by some kind of server, so it depends on how that server uses the content in the XML document. Even if you place the Javascript between <script> elements, if that server reading the XML document does not use this information for anything, it's in vain. Ideally you should find some public documentation about the allowed structure of the XML configuration file or get help on one of their support channels. But we cannot help further as we do not know how the XML is interpreted further.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply