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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to show funtion DOM

    Hi,
    I want o show function results, but I dont know how to do that.

    Code:
    show = function(t) { console.log(new Date(t).toString()); };
    getServertimeFromFacebook = function(cb) {
        ajax("https://api.facebook.com/method/fql.query?query=SELECT+now%28%29+FROM+link_stat+WHERE+url+%3D+%271.2%27&format=json", function(responsetext) {
             var obj = JSON.parse(responsetext);
             var ts = obj[0].anon,
                 tms = ts * 1000;
             cb(tms);
        });
    };
    Please hep me.

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Code:
    function show(t) { alert(new Date(t).toString()); };
    
    getServertimeFromFacebook = function(cb) {
        aGet("https://api.facebook.com/method/fql.query?query=SELECT+now%28%29+FROM+link_stat+WHERE+url+%3D+%271.2%27&format=json", function(responsetext) {
             var obj = JSON.parse(responsetext);
             var ts = obj[0].anon,
                 tms = ts * 1000;
             cb(responsetext);
        });
    };
    
    
    getServertimeFromFacebook(show);
    
    function aGet(turl,callback){var XHRt=new XMLHttpRequest;XHRt.onreadystatechange=function(){if(XHRt.readyState==4&&XHRt.status==200){callback(XHRt.responseText,XHRt);}};XHRt.open("GET",turl,true);XHRt.send();return XHRt;}
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Of course the debugging alert is just there for testing purposes - you'll need to replace that with some code to actually update the value into the page itself before you go live - unless you want people using the alert to disable JavaScript for your site.

    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by felgall View Post
    Of course the debugging alert is just there for testing purposes - you'll need to replace that with some code to actually update the value into the page itself before you go live - unless you want people using the alert to disable JavaScript for your site.

    where is that screenshot from? it looks ancient...

    none of the 4 current major browsers (ch/ie/sa/ff) i tested have that interface, so i don't think normal people will be disabling scripts from that.

    from a browser-ui viewpoint, that's just asinine design: My mom doesn't even know what scripts are, much less what the poor guys did to deserve execution...
    Last edited by rnd me; 12-06-2012 at 08:27 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by rnd me View Post
    where is that screenshot from? it looks ancient...

    none of the 4 current major browsers (ch/ie/sa/ff) i tested have that interface, so i don't think normal people will be disabling scripts from that.

    from a browser-ui viewpoint, that's just asinine design: My mom doesn't even know what scripts are, much less what the poor guys did to deserve execution...
    It is MODERN - the browsers that don't display the debugging checkboxes in the dialogs are the ancialt ones.

    Prior to 2005 alert confirm and prompt used to be the main ways JavaScript interacted with visitors to the page. Since then forms and being able to update the page itself have replaced those antiquated limited ways of interacting. That means that alert etc are now only useful for quick debugging of code and so extra checkboxes have been added to those dialogs to make them easier to use for debugging.

    The prior screenshot is from the CURRENT version of Opera.

    Firefox and Chrome both put a similar checkbox into all alerts generated by the page apart from the first one - but instead of disabling JavaScript completely checking that checkbox simply stops any further alert confirm or prompt dialogs from displaying in the page.

    Here's a screenshot of an alert from the CURRENT version of Firefox (where the alerts are simply counting with the first alert displaying '1' and this being the second alert).



    The alerts generated in the CURRENT version of Chrome are part way between the two with a title bar similar to Opera and content similar to Firefox.

    Internet Explorer is the only popular browser that doesn't display these additional checkboxes to aid in debugging (unless they have caught up with the other browsers with version 10 as I don't have a copy of IE10 to test with yet).


    ALL of the current browser versions except IE display debugging checkboxes in their alert confirm and prompt dialogs. It is as you say just asinine design on the part of the script author to display these checkboxes to your mom and others that don't know what scripts are - that's why I suggested getting rid of them before other people have access to your page.
    Last edited by felgall; 12-06-2012 at 09:05 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by felgall View Post
    It is MODERN - the browsers that don't display the debugging checkboxes in the dialogs are the ancialt ones.

    ALL of the current browser versions except IE display debugging checkboxes in their alert confirm and prompt dialogs. It is as you say just asinine design on the part of the script author to display these checkboxes to your mom and others that don't know what scripts are - that's why I suggested getting rid of them before other people have access to your page.
    the dialog snooze option does NOT disable JS.

    what you originally said was not to use alert() "unless you want people using the alert to disable JavaScript for your site."; a situation only in play for about 1/50 visitors given most web stats. it's an attention grabbing message to be sure, but one that is just not true for the vast majority of us.

    while i'm with you 150% as far as avoiding alert(), sell it using UX, not fear.
    on mobile, it's actually not as bad, and has an intuitive skin, so lets not drain the bathwater yet.

    its use by authors is not the best experience, but the default text on opera is literally ridiculous; no wonder it's stuck at 2%. The fact that the browser itself allows that kind of verbiage to encounter the user is just plain sad. It's as if Opera hasn't even done the self-narrated interaction observer studies. Firefox's is better, though even there, you have the jargon "dialog", a term i'd give my mom 50/50 odds of understanding.


    so, yes, don't use prompt(), but don't claim it's usage is as bad as Opera's mis-implementation.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by rnd me View Post
    the dialog snooze option does NOT disable JS.
    I agree that simple disabling the debugging dialog messages as Firefox and Chrome do is a better solution than what Opera implemented - Opera did implement their checkbox to turn off JavaScript quite a few years before Firefox and Chrome decided to catch up and overtake Opera's implementation with a more useful one (for debugging purposes but not if misused in live web pages).

    Even where the diaalog doesn't disable JavaScript it strill disables any further dialogs - which is exactly what you want if you are using them to debug a loop and have seen enough values to work out what is happening but which is not what you want when validating a form.

    With web page that use alerts to display error messages for form field validation the Opera solution of turning off JavaScript if the checkbox is checked means that once they do that they will be able to submit the form and have the server side validation tell them what is wrong. If the checkbox gets checked in Firefox or Chrome then they will not see any further error messages telling them what they need to fix but the JavaScript will still prevent them from submitting the form until they guess what they need to fix. To me the first of these is the better user experience.

    Since these dialogs are not intended to be used in live web pages their actual appearancetoday is irrelevant as no one other than the script author should ever see them. It was different back in the Netscape 4 (and earlier) days where they were useful in live pages - then their appearance did matter - and most of the info that they display that you are complaining about were deliberately added to reduce the security issues associated with their misuse.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you rnd me but I've got ivalid data prompt error.



    Do you know whats wrong?


  •  

    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
    •