load mbox using jquery or native javascript

593 views Asked by At

I have a predefined working website, that would be hard to redefine from top to bottom, but I am trying to implement some Test and Target using mboxes. On research I have found that the best place to implement mbox is using global mbox. As the structure needs to be setup on the go, i was planning to use some native javascript to add the globalmbox to the top of the page, like:

var mbox_html = document.createElement("div");
mbox_html.class="mboxGlobal";
//Script child to add to the top to create mbox
mbox_script = document.createElement("script");
mbox_script.type ="text/javascript";
mbox_script.textContent="mboxCreate('b_tntGlobal');";
document.body.insertBefore(mbox_script,document.body.firstChild);
document.body.insertBefore(mbox_html,document.body.firstChild);

Will this be effective implementation? Will mbox.js actually accept something like this, as I am adding this piece of code to the end of the page, and the DOM is already loaded before this is implemented

2

There are 2 answers

0
Mike Van Stan On

You can create and define where ever and whenever you'd like - your offer/experience just may not be available until you do so.

I'm not sure what you're trying to achieve but a simple:

//Define global mbox

mboxDefine('mboxDefaultRandom', 'Shoppable_Global_Clicks'); mboxDefine('mboxAnotherRandomMbox', 'Shoppable_Global_Add-to-Cart-Clicks');

mboxUpdate( 'Shoppable_Global_Add-to-Cart-Clicks', 'clicked=Y'); mboxUpdate( 'Shoppable_Global_Clicks');

Should suffice : )

0
Eduardo Chongkan On
if (mboxFactoryDefault.getMboxes().get("mboxDefaultLog").length()==0) {
    var d = document.createElement("div");
    d.id = "mboxDefaultLog_div";
    document.body.appendChild(d);
    mboxDefine("mboxDefaultLog_div", "mboxDefaultLog");
    mboxUpdate("mboxDefaultLog", "defaultOffer=true");
}

This is how I do a dynamic implementation.