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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How do you make an ios5 type notification system with javascript for your webpage?

    How do you make an ios5 type notification system with javascript for your webpage?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by TheElect2049 View Post
    How do you make an ios5 type notification system with javascript for your webpage?
    You don't. Javascript cannot (for this purpose) communicate with the server.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,371
    Thanks
    11
    Thanked 591 Times in 572 Posts
    Quote Originally Posted by TheElect2049 View Post
    How do you make an ios5 type notification system with javascript for your webpage?
    afaik, only chrome supports desktop notifications. Still, that's not bad because chrome works on all desktop platforms, and can be used just for notifications.


    example:

    Code:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<title>desktop notification test</title>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body> 
    
    <input id="msgVal" value="Hello World" />
    <input type="button" value="Enable" 
        onclick="enableChromeMessages(); this.value='Notify'; this.onclick=function(){notify(el('msgVal').value);}; " />
      
    <script type='text/javascript'>
    
    function el(tid) {return document.getElementById(tid);}
    
    
    var wn=window.webkitNotifications;
    
    function enableChromeMessages(){  var wn=window.webkitNotifications;
    	if(wn && wn.checkPermission() == 1){
    		    wn.requestPermission(turnOnNotesAfterUserApproval);
    	}//end if chrome notifications
    	
    	function turnOnNotesAfterUserApproval(){	
    		notify.fn=chromeNotifyInternal; 
    	 }//end turn on notes (perm req cb)
    }//end enableChromeMessages()
    
    
    
    function notify(strMsg){
    	if( wn && wn.checkPermission() == 0 ){
    		notify.fn=chromeNotifyInternal;
    		notify.on=true;
    	}//end if chrome notifications
    
    	notify.fn(strMsg);
    
    };notify.fn=String; //end notify()
    
    
    function chromeNotifyInternal(strMsg){ 
          var n=window.webkitNotifications.createNotification('http://www.vcgcb.ca.gov/images/icons/Alert48.png',
            'Widgets Inc Intranet Says: ', 
            strMsg
           );
           n.show();
    };//end cb()
    
    </script>
    </body>
    </html>

    @Philip M : i don't see what a server has to do with anything related to this question. i still have no idea what you even mean that "Javascript cannot communicate with the server", that's patently false and an absurd claim for any respectable coder to make. ajax, websockets, eventSource, iframe, img pings; none of those communicate with the server? huh? i suggest you re-learn what "communicate" means, because it's happening on the web every day. Heck, this forum itself uses javascript to communicate your misleading statements to the server; watch firebug as you edit a post if you don't believe me.
    Last edited by rnd me; 03-08-2012 at 08:57 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • Users who have thanked rnd me for this post:

    webdev1958 (03-09-2012)

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by rnd me View Post

    @Philip M : i don't see what a server has to do with anything related to this question. i still have no idea what you even mean that "Javascript cannot communicate with the server", that's patently false and an absurd claim for any respectable coder to make. ajax, websockets, eventSource, iframe, img pings; none of those communicate with the server? huh? i suggest you re-learn what "communicate" means, because it's happening on the web every day. Heck, this forum itself uses javascript to communicate your misleading statements to the server; watch firebug as you edit a post if you don't believe me.
    I did say "for this purpose". Perhaps it might have been better phrased as "in this context". There is nothing in the OP's question which has any relevance to ajax, websockets, eventSource, iframe or img pings. But I was not aware that Chrome now supports desktop notifications.

    I do agree that HTML5 has changed things very considerably. But HTML5 is only in a draft stage, far from finalised, and is only patchily implemented, and then not consistently in different browsers. webdev1958/bullant considers it currently half baked! It will be several - even many- years before HTML5 is universally and consistently implemented. Until then we must (except for certain very specialised applications) continue to code in ways which are in accordance with HTML4 and the great majority of existing browsers.
    Last edited by Philip M; 03-09-2012 at 08:33 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,371
    Thanks
    11
    Thanked 591 Times in 572 Posts
    Quote Originally Posted by Philip M View Post
    It will be several - even many- years before HTML5 is universally and consistently implemented. Until then we must (except for certain very specialised applications) continue to code in ways which are in accordance with HTML4 and the great majority of existing browsers.
    phones get new browsers every two years, when people get new phones. or when they update on droid. The latest mobile browsers are as good as ie9. clearly, when building a mobile site you don't need to worry about IE7.

    You might be surprised how much of HTML5/CSS3 is ready to go. according to http://www.caniuse.com/, if you support ie7 you get 9 of those features 100% xbrowser. IE8 takes it up to 19 features, and IE9 takes it up to 42 (of 109).

    that's assuming the following other min-supported versions:
    Code:
    Firefox	Chrome	Safari	Opera	iOS 	Android Browser
    10	16	5.1	11.6	5	2.3

    that's just counting the 100% standard stuff.

    dozens more are 100% available with browser-prefixes like -webkit-.

    dozens more beyond that are possible to support using polyfills. a polyfill is js code that reads the standard-compliant code, and reproduces the intended behavior. form validation that reads pattern attribs in IE is a perfect example. json2.js is the most famous polyfill.


    the point is that there's no reason to wait on a lot of things.
    i'm not saying require IE10 to view the page, but don't be shy about progressive enhancement. on our public site at work 100k+/month, a full 3/4 of our visitors are using a browser supporting 75% of known html5 features tracked on caniuse. Clearly, IE7 is the liability, but it's disappearing a lot faster than 8 did, already being down to 5% on the site.
    Last edited by rnd me; 03-09-2012 at 09:43 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by Philip M View Post
    You don't. Javascript cannot (for this purpose) communicate with the server.
    The question is related to mobile device and not a server. Mobile browsers are HTML5-based browsers and support new JavaScript APIs that can access hardware functionalities like GPS location, screen orientation, etc. In this day and age of smartphones and tablets, you cannot limit JavaScript to desktop browsers only.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by glenngv View Post
    The question is related to mobile device and not a server. Mobile browsers are HTML5-based browsers and support new JavaScript APIs that can access hardware functionalities like GPS location, screen orientation, etc. In this day and age of smartphones and tablets, you cannot limit JavaScript to desktop browsers only.
    A fair point. I am not knowledgeable about mobile devices, so tend to forget about them.

    In parentheses, I would regard the word "communicate" to be a two-way process. No Javascript technique I know of will allow the writing of data to a file on the server.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #8
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    [ot[

    Quote Originally Posted by Philip M View Post
    webdev1958 considers it currently half baked!
    and so does felgall and DeathShadow60 and a few others over at sitepoint . Well actually , DS60 thinks it's not worth baking at all and makes some very good points.

    [/ot]
    Last edited by webdev1958; 03-09-2012 at 11:52 AM.

  • #9
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    [ot]

    Quote Originally Posted by Philip M View Post
    No Javascript technique I know of will allow the writing of data to a file on the server.
    AJAX (which is javascript) can send data to a server side script for ouputing to a file on the server or to a database.

    [/ot]

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,371
    Thanks
    11
    Thanked 591 Times in 572 Posts
    Quote Originally Posted by Philip M View Post
    In parentheses, I would regard the word "communicate" to be a two-way process. No Javascript technique I know of will allow the writing of data to a file on the server.
    (ot)
    the apache running the shared webspace at the college i went to (uiuc) supported webDAV. that meant i could save using a PUT request, if the folder had public or personal write access enabled. If i weren't logged in and tried to save, it would prompt via basic auth for a username and password. all this with just http, i wrote no server-side code to do this. i'll pm you a demo if you want, it's still online.


    It is possible, it's just a bad idea for security reasons under most circumstances.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by rnd me View Post
    (ot)
    the apache running the shared webspace at the college i went to (uiuc) supported webDAV. that meant i could save using a PUT request, if the folder had public or personal write access enabled. If i weren't logged in and tried to save, it would prompt via basic auth for a username and password. all this with just http, i wrote no server-side code to do this. i'll pm you a demo if you want, it's still online.

    It is possible, it's just a bad idea for security reasons under most circumstances.
    You mean, sort of like crossing over a 12-lane motorway on foot?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #12
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    Quote Originally Posted by Philip M View Post
    No Javascript technique I know of will allow the writing of data to a file on the server.
    I have seen your presence in threads that discuss non-browser javascript, as well as the ActiveXObjects available to all versions of IE that can do all kinds of things that browser code shouldn't be allowed to do, if a user prompt allows the ActiveXObject to be initialized. Perhaps that should read
    "No Javascript technique I know of, available to all browsers, will allow the writing of data to a file on the server."
    Allwisend bin ich nicht, doch viel ist mir bewursst
    -Goethe

  • Users who have thanked blaze4218 for this post:

    Philip M (03-09-2012)

  • #13
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by blaze4218 View Post
    I have seen your presence in threads that discuss non-browser javascript, as well as the ActiveXObjects available to all versions of IE that can do all kinds of things that browser code shouldn't be allowed to do, if a user prompt allows the ActiveXObject to be initialized. Perhaps that should read
    "No Javascript technique I know of, available to all browsers, will allow the writing of data to a file on the server."
    My understanding is that ActiveX is not Javascript. I do agree that I intend to refer to Javascript running in a browser. I agree that AJAX is Javascript - but it cannot write to a file on the server unaided by server-side scripting.

    I think felgall has explained things very clearly:-

    http://javascript.about.com/od/hints.../a/activex.htm
    Last edited by Philip M; 03-09-2012 at 05:53 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #14
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    Quote Originally Posted by Philip M View Post
    My understanding is that ActiveX is not Javascript
    You are correct.

    What I see happening here is based very much on our own definition/usage of what should be the same word...

    JavaScript is essentially ECMAScript as defined by the consortium. However, no browser implements this in the same way, each providing their own special features. Technically JScript, and ActiveX are not JavaScript in the same way as Mozilla's "local" variable initialization is not JavaScript... or webkit's "-webkit-box-reflect" is not CSS... but if you put local in the same Script tag as ActiveX, both will work on the intended browser and fail on the other! So if it's not "JavaScript", then why does it work in a script tag that isolates, and executes only JavaScript?

    AJAX was once only available through ActiveX, but when the other browsers saw that it could work- They "borrowed" it and called it something different. Now it's JavaScript?? Or was it always JavaScript, that could only be used in IE?

    If we only define the core language as JavaScript and only if it works on every browser, then object detection wouldn't exist (or, at least, it wouldn't be called JavaScript...), because it is testing for all the features that are *not* JavaScript.

    I get that ActiveX is not JavaScript, and that JScript is a wholly seperate creature. But, by your arguments, why don't I ever see you write "local is not JavaScript"? Instead you are more inclined to pen "local is not standardized". Seems like the same old IE bashing to me... (not that I'm a fan!)
    Allwisend bin ich nicht, doch viel ist mir bewursst
    -Goethe

  • #15
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,371
    Thanks
    11
    Thanked 591 Times in 572 Posts
    Quote Originally Posted by Philip M View Post
    I agree that AJAX is Javascript - but it cannot write to a file on the server unaided by server-side scripting.
    webDAV is not scripting, it's part of the apache setup usually. When i think "server-side scripting", i think index.php or default.asp or default.aspx, or whatever. That's not the case with webDAV, so your statement is false.


    proof: https://netfiles.uiuc.edu/dldavis2/writeable/
    Last edited by rnd me; 03-09-2012 at 09:27 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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