aroth
aroth

Reputation: 54846

Phonegap - HTML files that don't include .htm/.html in the filename

Using Phonegap it is trivial to programmatically switch from one page to another using code along the lines of:

window.location.href = "someDestination.html";

However, I've noticed that for some reason, this will not work if the extension on the destination file is not '.html'. For example, the following code:

window.location.href = "someOtherDestination";

...will cause PhoneGap to fail with the following error message:

Failed to load webpage with error: Frame load interrupted

I would have thought that PhoneGap would be intelligent enough to inspect the contents of the destination file to determine if it is a valid webpage (for instance, by looking for a <html> tag), rather than attempting to rely on superfluous information like the file extension. But this doesn't seem to be the case.

So my question is, why does PhoneGap care whether or not the filename ends in .htm/.html, and how do I make it stop caring about this?

Upvotes: 1

Views: 821

Answers (2)

Benjamin H
Benjamin H

Reputation: 5484

I too ran into this Cordova/Phonegap 3.0

Near the top of my page I had a redirect. Not "responsive design", I know, but a good temporary fix for showing a UI that fits in an iPhone.

<script>
  if (navigator.userAgent.match(/(iPhone|iPod).*AppleWebKit/i)) {
    window.location = "iphone/";
  }
</script>

Failed with the same error. Changing it to

window.location = "iphone/index.html";

fixed the error

Upvotes: 0

Vinay
Vinay

Reputation: 6342

LOL:

function getHTMLFile(str) {
    return str + '.html';
}

function getHTMFile(str) {
    return str + '.htm';
}

;-)

No, but seriously this is part of the window.location.href's spec. It's not a PhoneGap specific issue. You will not be able to override this simply with javascript (see this).

Upvotes: 2

Related Questions