QX.js Scripting Guide

Working with Hyperlinks

URL hyperlinks

URL hyperlinks on text

To apply URL hyperlinks on text:

  1. Get the DOM of the active layout.

  2. Get the desired <qx-box> , <qx-p> and <qx-span> node .

  3. Create the element <qx-a> and set its 'href' attribute to 'www.google.com' and 'title' attribute to 'google'.

  4. Append the span inside the newly created <qx-a>.

  5. Append the <qx-a> inside the paragraph.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box');
    var paras = boxes[0].getElementsByTagName('qx-p');
    var spans=boxes[0].getElementsByTagName('qx-span');
    var url_anchor=document.createElement('qx-a');
    url_anchor.setAttribute('href','www.google.com');
    url_anchor.setAttribute('title','google');
    url_anchor.appendChild(spans[0]);
    paras[0].appendChild(url_anchor);

URL hyperlinks on box

To apply URL hyperlinks on box:

  1. Get the DOM of the active layout.

  2. Get the desired <qx-spread> and <qx-box> node .

  3. Create the element <qx-a> and set its 'href' attribute to 'www.google.com' and 'title' attribute to 'google'.

  4. Append the box inside the newly created <qx-a>.

  5. Append the <qx-a> inside the spread.

    var layout=app.activeLayoutDOM();
    var spreads=layout.getElementsByTagName('qx-spread');
    var boxes=layout.getElementsByTagName('qx-box');
    var url_anchor=document.createElement('qx-a');
    url_anchor.setAttribute('href','www.google.com');
    url_anchor.setAttribute('title','google');
    url_anchor.appendChild(boxes[0]);
    spreads[0].appendChild(url_anchor);

Anchor hyperlinks

Creating new anchor

To create a new anchor:

  1. et the DOM of the active layout.

  2. Get the desired <qx-box> and <qx-p> node .

  3. Create the element <qx-bookmark> and set its 'id'  attribute to 'anchor'.

  4. Create the element <qx-span> and set its inner text to 'NEW BOOKMARK'.

  5. Append the bookmark inside the paragraph.

  6. Append the span inside the paragraph.

    var layout = app.activeLayoutDOM();
    var boxes = layout.getElementsByTagName('qx-box');
    var paras= boxes[0].getElementsByTagName('qx-p');
    var new_bookmark=document.createElement('qx-bookmark');
    new_bookmark.setAttribute('id','anchor');
    var new_span=document.createElement('qx-span');
    new_span.innerText='NEW BOOKMARK';
    paras[0].appendChild(new_bookmark);
    paras[0].appendChild(new_span);

Anchor hyperlinks on text

To apply anchor hyperlinks on text:

  1. Get the DOM of the active layout.

  2. Get the desired <qx-box> , <qx-p> and <qx-span> node .

  3. Create a new bookmark as mentioned in the above section.

  4. Create the element <qx-a> and set its 'href'  attribute to the id of the bookmark.

  5. Append the span inside the newly created <qx-a>.

  6. Append the <qx-a> inside the paragraph.

var layout = app.activeLayoutDOM();
var boxes = layout.getElementsByTagName('qx-box');
var paras=boxes[0].getElementsByTagName('qx-p');
var spans=paras[0].getElementsByTagName('qx-span');
var anchor_span=boxes[1].getElementsByTagName('qx-span');
anchor_span[0].innerHTML='I am Anchor for Box 1';
var new_bookmark=document.createElement('qx-bookmark');
new_bookmark.setAttribute('id','anchor');
var list=anchor_span[0].parentNode;
list.insertBefore(new_bookmark,list.childNodes[0]);
var new_anchor_url=document.createElement('qx-a');
new_anchor_url.setAttribute('href','#anchor');
new_anchor_url.appendChild(spans[0]);
paras[0].appendChild(new_anchor_url);

Page hyperlinks

Page hyperlinks on text

To apply page hyperlinks on text:

  1. Get the DOM of the active layout.

  2. Get the desired <qx-box> , <qx-p> and <qx-span> node .

  3. Create the element <qx-a> and set its 'href'  attribute to '#page=2'.

  4. Append the span inside the newly created <qx-a>.

  5. Append the <qx-a> inside the paragraph.

    var layout=app.activeLayoutDOM();
    var boxes=layout.getElementsByTagName('qx-box');
    var paras = boxes[0].getElementsByTagName('qx-p');
    var spans=boxes[0].getElementsByTagName('qx-span');
    var page_anchor=document.createElement('qx-a');
    page_anchor.setAttribute('href','#page=2');
    page_anchor.appendChild(spans[0]);
    paras[0].appendChild(page_anchor);

Page hyperlinks on box

To apply page hyperlinks on box:

  1. Get the DOM of the active layout.

  2. Get the desired <qx-spread> and <qx-box> node .

  3. Create the element <qx-a> and set its 'href'  attribute to '#page=2'.

  4. Append the box inside the newly created <qx-a>.

  5. Append the <qx-a> inside the spread.

var layout=app.activeLayoutDOM();
var spreads=layout.getElementsByTagName('qx-spread');
var boxes=layout.getElementsByTagName('qx-box');
var page_anchor=document.createElement('qx-a');
page_anchor.setAttribute('href','#page=2');
page_anchor.appendChild(boxes[0]);
spreads[0].appendChild(page_anchor);