...

View Full Version : How do you make an ios5 type notification system with javascript for your webpage?



TheElect2049
03-08-2012, 07:28 AM
How do you make an ios5 type notification system with javascript for your webpage?

Philip M
03-08-2012, 09:43 AM
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.

rnd me
03-08-2012, 09:48 PM
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:


<!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 (http://dictionary.reference.com/browse/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.

Philip M
03-09-2012, 08:35 AM
@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 (http://dictionary.reference.com/browse/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.

rnd me
03-09-2012, 10:41 AM
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:

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.

glenngv
03-09-2012, 10:48 AM
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.

Philip M
03-09-2012, 11:12 AM
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.

webdev1958
03-09-2012, 12:39 PM
webdev1958 considers it currently half baked! [/QUOTE]

and so does felgall and DeathShadow60 and a few others over at sitepoint :). Well actually , DS60 thinks it's not worth baking at all :D and makes some very good points.

webdev1958
03-09-2012, 12:50 PM
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.

rnd me
03-09-2012, 06:19 PM
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.

Philip M
03-09-2012, 06:27 PM
(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? :D

blaze4218
03-09-2012, 06:33 PM
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."

Philip M
03-09-2012, 06:48 PM
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/hintsandtips/a/activex.htm

blaze4218
03-09-2012, 07:18 PM
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!)

rnd me
03-09-2012, 10:23 PM
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/

Philip M
03-10-2012, 08:39 AM
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/

I bow to your superior knowledge. But your link does nothing - what is it supposed to do? I have the idea that very many people here have not encountered webDAV (Web-based Distributed Authoring and Versioning). Doubtless it is supported in universities, software development teams and the like. I am sorry to say that I do not see any connection at all between webDAV and Javascript. I did not for one moment say or imply that it was not possible to write to files on the server - that would be ridiculous. What I did (and still do) say is that Javascript cannot write to a file on the server unaided by server-side scripting.

I think that you should bear in mind the context in which the question is typically asked. Many - perhaps most - people coming to this forum want to develop a relatively simple personal or small business website. They often have little or no knowledge of coding in any language. It is very common that "starter" packages offered by ISPs do not include any access to server-side languages - just web space. It is natural that the question is asked - can I use Javascript (which is available to me) to write to/read from files on the server? The sensible answer to that question is that although AJAX can read from a file it is not possible using (just) Javascript to write to it. So, for example, Fred cannot add comments to the site that Jane can read. Dragging in the likes of webDAV is IMHO unhelpful.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum