Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    71
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Making a function in dojo display items

    Hi all,

    In dojo, I am detecting browser with /has and /sniff and I using vanilla JS to then detect platform and display them correctly in a list of dt's and dl's but, I only want to populate a paragraph with the information that the function returns and not have all the other useless Is this IE?, Is this FF etc.

    http://jsfiddle.net/VfC54/4/

    Thank you all.
    Last edited by pcproff; 09-23-2012 at 04:30 AM.

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,918
    Thanks
    56
    Thanked 545 Times in 542 Posts
    I don't know anything about DOM transversal in dojo, so I had to make a test for the previous element browser compatibility. This is the basic idea, anyway. I'm sure you could dojo it up if you like:

    Code:
    var prev=document.body.previousElementSibling?'previousElementSibling' : 'previousSibling';
                
      arrayUtil.forEach(["ie", "mozilla", "ff", "opera", "webkit", "chrome"], function(n){
        var el=dom.byId("answerIs" + n)
          el.innerHTML = makeFancyAnswer(n);
         if (makeFancyAnswer(n)=="No"){
             el.parentNode.removeChild(el[prev]);
    el.parentNode.removeChild(el)         
             }
      });

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,918
    Thanks
    56
    Thanked 545 Times in 542 Posts
    ... but why don't you just do:

    Code:
    <dd id="answer"></dd>
    
    
    var browsers={ff:"Firefox",ie:"Internet Explorer", mozilla:"Mozilla", opera:"Opera", webkit:"Webkit", chrome:"Chrome"}
    
        if(has(browser)){
          return "You are running "+browsers[browser]+ " version " + has(browser) + " <br/> your operating system is " + OS + " <br/> running on " + platform;
        }else{
          return "No";
        }
      }
    
             
      arrayUtil.forEach(["ie", "mozilla", "ff", "opera", "webkit", "chrome"], function(n){
         if (makeFancyAnswer(n)!="No"){
            dom.byId("answer").innerHTML = makeFancyAnswer(n);        
             }
      });

  • Users who have thanked xelawho for this post:

    pcproff (09-24-2012)

  • #4
    New Coder
    Join Date
    Nov 2006
    Posts
    71
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hey thanks for the answer! I will try this tomorrow and let you know.

  • #5
    New Coder
    Join Date
    Nov 2006
    Posts
    71
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Thank for your answer this works like a charm. I will closely examine what your thinking was behind this solution.

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,918
    Thanks
    56
    Thanked 545 Times in 542 Posts
    if you went with the second (simplified) version, I would suggest a small change for when there are multiple positive responses (like Chrome+Webkit):

    Code:
    arrayUtil.forEach(["ie", "mozilla", "ff", "opera", "webkit", "chrome"], function(n){
         if (makeFancyAnswer(n)!="No"){
            dom.byId("answer").innerHTML += makeFancyAnswer(n)+"<br>";        
             }
      });


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •