Feeds

How I wrote an iPhone application

An introduction to the world of mobile Web 2.0

Remote control for virtualized desktops

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>

Remote control for virtualized desktops

More from The Register

next story
You! AT&T! The only thing 'unlimited' about you is your CHEEK, growl feds
Man, we did everything but knock on their doors - carrier
The DRUGSTORES DON'T WORK, CVS makes IT WORSE ... for Apple Pay
Goog Wallet apparently also spurned in NFC lockdown
Watch out, Samsung and Apple: Xiaomi's No 3 in smartphones now
From obscurity to selling 19 million mobes a quarter
Brazil greenlights $200m internet cable to Europe in bid to outfox NSA
Only one problem: it won't make the slightest difference. And they know it
Wanna hop carriers with your iPad's Apple SIM? AVOID AT&T
Unless you want your network-swapping tech disabled for good, that is
Knocking Knox: Samsung DENIES vuln claims, says mysterious blogger is a JOKER
But YES, system does store encryption key on the device
prev story

Whitepapers

Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
Getting started with customer-focused identity management
Learn why identity is a fundamental requirement to digital growth, and how without it there is no way to identify and engage customers in a meaningful way.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
Top 5 reasons to deploy VMware with Tegile
Data demand and the rise of virtualization is challenging IT teams to deliver storage performance, scalability and capacity that can keep up, while maximizing efficiency.
Reducing the cost and complexity of web vulnerability management
How using vulnerability assessments to identify exploitable weaknesses and take corrective action can reduce the risk of hackers finding your site and attacking it.