I don't understand why my code isn't running in order... The code below doesn't execute the document.write part, but it executes the part after it just fine. I think it has something to do with the timing, giving the browser to execute the . I tried using setTimeout in some parts, but it's either not working, or I'm doing it wrong.
function isBrowserMobile()
{
var iPadAgent = navigator.userAgent.match(/iPad/i) != null;
var iPodAgent = navigator.userAgent.match(/iPhone/i) != null;
var AndroidAgent = navigator.userAgent.match(/Android/i) != null;
var webOSAgent = navigator.userAgent.match(/webOS/i) != null;
if (iPadAgent || iPodAgent || AndroidAgent || webOSAgent)
{
document.write("<body bgcolor='Orange'><b>Mobile browser detected!</b></body>");
var choice = confirm("Do you want to visit the mobile site?")
if (choice)
mobile();
else
desktop();
}
}
iPadAgent || iPodAgent || AndroidAgent || webOSAgentisfalse, thendocument.writeis not executed.desktop()? Or is it a NOOP?bodytag withdiv.