javascripthtmldommuse

Adobe Muse shows document.createElement link, but won't preview


I'm trying to show a link only at certain times of the day.

The link is visible within Adobe Muse, but is hidden on browser.

Here's my code

<script type="text/javascript">

var day= new Date();

var hr= day.getUTCHours();


if ((hr == 0) || (hr == 1) || (hr == 2) || (hr == 3) || (hr == 4) || (hr == 5) || (hr == 6) || (hr == 7) || (hr == 8) || (hr == 9) || (hr == 10) || (hr == 11) || (hr == 12) || (hr == 13) || (hr == 22) || (hr == 23)) {   var a = document.createElement('a'); var linkText = document.createTextNode("Example"); a.appendChild(linkText); a.title = "Example"; a.style.fontSize = "16px"; a.style.color="#C31E2F"; a.href = "http://www.example.com/"; document.body.appendChild(a);}

if ((hr == 14) || (hr == 15) || (hr == 16) || (hr == 17) || (hr == 18) || (hr == 19) || (hr == 20) || (hr == 21)) { document.write("<br><font>CALL TOLL FREE:xxx-xxx-xxxx</font></br>");}


Solution

  • Ended up trashing most of the existing code. I think document.createElement was causing the problem.

    Here's what I'm using instead.

    <script type="text/javascript">

    var day= new Date();
    var hr= day.getUTCHours();
    if ((hr>=0 && hr<13) || (hr>=22 && hr<=23)) { 
    document.write('<font>Example</font>'.link('http://www.example.com/')); }
    else { document.write("<font>CALL TOLL FREE:xxx-xxx-xxxx</font>"); }