Feeds

How I wrote an iPhone application

An introduction to the world of mobile Web 2.0

Gartner critical capabilities for enterprise endpoint backup

But we do have a working application which will also function on the Nokia implementation of Safari, but looks very odd on the desktop version.

Mainly we discovered that JavaScript is really irritating to program in, and that the idea of write-once-run-anywhere remains as true as it ever was. We also got annoyed at the security restrictions and the lack of comprehensive documentation, though at least the latter problem should fade with time.

We also decided that we're not going to develop anything else for the iPhone until there's a proper development kit, allowing the use of a proper programming language, and some decent documentation too. ®

<script language="JavaScript">
//<!-- JavaScript here
  
  //This one thinks it's an object
  var myRequest = new XMLHttpRequest();
  
  //This is the text we're going to change the word "iPhone" to
  var changeTo = "";
  
  //This is our home page, and the site that leaving will unload the app
  var home = 'http://www.theregister.co.uk';
  
  function startUp() {
    changeTo = readCookie("newName")
    if (changeTo == null) {
      changeTo = window.prompt("So what would better suit the iPhone?");
      createCookie("newName", changeTo, 1);
    }
    loadRegister(home);
  }
  
  function loadRegister(targetURL) {
  
    //targetDomain is set to a string containing the site (but not directories or file) that the user clicked on
    var targetDomain = targetURL.substring(targetURL.indexOf(".", 8)+1, targetURL.indexOf("/", 8));

    //We compare that to our home page
    if (home.indexOf(targetDomain) == -1) {
      alert("Moving Off Site: " + targetDomain);
      //This line unloads this application, as the targetURL replaces this document
      parent.parent.location=targetURL;
    }

    //Then we load the page
    myRequest.open("GET", targetURL);
    myRequest.onload = targetLoaded;
    myRequest.send();
  }
  
  function targetLoaded() {
    var loadedSite = myRequest.responseText;
    
    loadedSite = loadedSite.replace(/iPhone /g, changeTo + " ");
    loadedSite = loadedSite.replace(/ iPhone/g, " " + changeTo);

    var counter;

    var loadedDocument = parent.frames[0].document;
    
    loadedDocument.open();
    loadedDocument.write(loadedSite);
    loadedDocument.close();
    //This is our horrible bodge which waits 10 seconds for the page to load
    setTimeout('pageLoaded()', 10000);
  }
  
  function pageLoaded() {
    //This loops through every link on the page (241 on the El Reg home page when we were testing this) and adds an "onclick" even listener
    for (i=0; i < parent.frames[0].document.links.length; i++) {
      parent.frames[0].document.links[i].onclick = linkClicked;
    }
  }
  
  function linkClicked() {
    loadRegister(this.href);
    //We return "false" so the browser dosen't attempt to load the link clicked on.
    return false;
  }
  
  function returnHome() {
    loadRegister(home);
  }
  
  function changeName() {
    eraseCookie("newName");
    changeTo = window.prompt("So what would better suit the iPhone?");
    createCookie("newName", changeTo, 1);
  }
  
  function createCookie(name,value,days) {
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
  }
  function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
  }
  function eraseCookie(name) {
        createCookie(name,"",-1);
  }
//-->
</script>

Secure remote control for conventional and virtual desktops

More from The Register

next story
6 Obvious Reasons Why Facebook Will Ban This Article (Thank God)
Clampdown on clickbait ... and El Reg is OK with this
So, Apple won't sell cheap kit? Prepare the iOS garden wall WRECKING BALL
It can throw the low cost race if it looks to the cloud
EE accused of silencing customer gripes on social media pages
Hello. HELLO. Can EVERYTHING EVERYWHERE HEAR ME?!
Time Warner Cable customers SQUEAL as US network goes offline
A rude awakening: North Americans greeted with outage drama
Shoot-em-up: Sony Online Entertainment hit by 'large scale DDoS attack'
Games disrupted as firm struggles to control network
BT customers face broadband and landline price hikes
Poor punters won't be affected, telecoms giant claims
Netflix swallows yet another bitter pill, inks peering deal with TWC
Net neutrality crusader once again pays up for priority access
prev story

Whitepapers

Best practices for enterprise data
Discussing how technology providers have innovated in order to solve new challenges, creating a new framework for enterprise data.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Advanced data protection for your virtualized environments
Find a natural fit for optimizing protection for the often resource-constrained data protection process found in virtual environments.
How modern custom applications can spur business growth
Learn how to create, deploy and manage custom applications without consuming or expanding the need for scarce, expensive IT resources.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?