iPhone pop-up choice window
Having fun with auto detection on the iPhone and then presenting the user with the choice of jumping directly to the app store and the application of choice.
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
input_box = confirm("Would you like to download Carl's favourite iphone application?");
if (input_box == true) {
// Output when OK is clicked
window.location = "itms://itunes.apple.com/us/app/angry-birds-hd/id364234221?mt=8";
}
else {
}
}
Firstly
Detect iPhone Safari
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {}
Next
Declare confirmation box, input_box
input_box = confirm("Would you like to download Carl's favourite iphone application?");
Lastly
Capture button clicked
if (input_box == true) {
// Output when OK is clicked
window.location = "itms://itunes.apple.com/us/app/angry-birds-hd/id364234221?mt=8";
} else { // Run cancel process code }
For working example see my portfolio site;
http://www.carlbruiners.co.uk/iphonedetectiondemo.htm
*Note: works only when view through iPhone, feel free to rip the page down using a desktop browser, or using FF change the HTTP agent to view iPhone output.
After Googling for 10 minutes I got fedup with crap tech tutorials, lack on consistancy, so I knocked up the above.
Code formatter
I started this morning looking for a code formater for blogger and I found;
http://formatmysourcecode.blogspot.com/
It was nice but there were no color coding options for the code. I dug further and found the following;
http://www.manoli.net/csharpformat/
Which is great for c#, vb.net and t-sql, but it isn't blogger friendly (didn't generate all the CSS inline).
What I have done for this site is to use the ideal of blogger friendly code formating from http://formatmysourcecode.blogspot.com/ and merge it with http://www.manoli.net/csharpformat/.
Another problem was that whilst I had now worked out how to generate the right look and feel for .NET / SQL, I didn't have a JavaScript formater. I found http://www.felgall.com/jsformat.htm, which is great but again I have had to combine this formater with the idea of the http://www.manoli.net/csharpformat/
So after all the messing around I have downloaded http://www.manoli.net/csharpformat/ source code and will be adding the following functionality;
- Blogger friendly formatting
- JS formatting
- CSS formatting
As soon as its completed I'll post in on my Portfolio site (http://www.carlbruiners.co.uk) for you all to download and use.
Useful JavaScript Luhn Check
For those who work with handling credit card information you have either or soon will need to carry out a luhn check, below is a useful JavaScript luhn check;
function checkCC(s) {
var i, n, c, r, t;
r = "";
for (i = 0; i < s.length; i++) {
c = parseInt(s.charAt(i), 10);
if (c >= 0 && c <= 9) r = c + r;
}
if (r.length <= 1) return false;
t = "";
for (i = 0; i < r.length; i++) {
c = parseInt(r.charAt(i), 10);
if (i % 2 != 0) c *= 2;
t = t + c;
}
n = 0;
for (i = 0; i < t.length; i++) {
c = parseInt(t.charAt(i), 10);
n = n + c;
}
if (n != 0 && n % 10 == 0) return true;
else return false;
}
function validateForm(f) {
var s = f.value;
if (checkCC(s)) alert("OK");
else alert("Please check your card number");
return false;
}
//]]></script>
I haven't added in checking the first number/s validation, as I have found there to be an inconsistency as to what number/s are used on what card type (an example was that I was told by one bank that a Maestro card couldn't start with 67, only Solo, but I have a Maestro card that does!)
I'll be posting a vb.net and c# version soon, as I still can't believe how many of you Dev's rely completely on client side JS as your only validation method.
I specialise in all things Agile (XP, Kanban, Lean), in particular Scrum. I have a passion for taking on 'problem' projects / teams and turning them into a sucess as well as promoting automated test driven practices.




