Windows Phone: trying to do `location = local file` but fails

536 views
Skip to first unread message

Remy Sharp

unread,
Aug 22, 2012, 7:49:39 AM8/22/12
to phon...@googlegroups.com
I've got a fairly simple app that writes some HTML to the local persistent file system on the device and once all loaded, it does:

`window.location = file.toURL()`

It works fine on iOS & Android, but on the Windows 7 Phone, instead of reloading, it throws up an "Origin Error" and doesn't let the location refresh happen.

I've noticed the `file.toURL()` yields `\\page.html' (when the file is called page.html) - but I guess that sounds right.

Any tips?  

Or has anyone managed to redirect a PhoneGap windows app to a newly created file?

Cheers,

- Remy

Christophe Guilmart

unread,
Aug 23, 2012, 12:06:34 PM8/23/12
to phon...@googlegroups.com
while I got no experience with your use case, I can tell you that WP manage the URL inside the phonegap app differenlty. just log windows.location of your home page to see the weird prefix WP use.
also, try to play with "\" VS "/". the "\\" does not sound right to me. try with hard coded URL to make some test...

But the "origin error" seem to indicate one of the many problem that the strict security implementation of karma bring to developers. remeber, that since phonegap use local files, you don't have a valide domain as origin.

have you try an iframe ? (no clue if this is possible. just throwing ideas...)

good luck, keep us posted.

Remy Sharp

unread,
Aug 23, 2012, 12:08:45 PM8/23/12
to phon...@googlegroups.com
I've tried a bunch of different urls, but none of them get to the saved page.

I will try an iframe as that could confirm that there's some funky
security around serving local files. I do hope that's not the case
though :(

On 23 August 2012 17:06, Christophe Guilmart
> --
> -- You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com
>
> To compile in the cloud, check out build.phonegap.com
>
>



--
I'm running a developer toolkit workshop - a choice of 6 topics,
run by 3 teachers, 1 day - £220:
https://leftlogic.stagehq.com/events/1518
___________________________

email & IM ~ re...@leftlogic.com
twitter ~ @rem
web ~ http://leftlogic.com
blog ~ http://remysharp.com

mob ~ +44 (0) 7590 497 258
tel ~ +44 (0) 1273 557744
fax ~ +44 (0) 1273 806580

Left Logic Ltd. Registered in England and Wales (registered no. 05926047).
Registered Office: 44 Burstead Close, Brighton, BN1 7HT, United Kingdom.
VAT registration: 993 1266 95

John Wards

unread,
Aug 24, 2012, 2:39:51 PM8/24/12
to phon...@googlegroups.com
Hmm is it just locally created files? Do existing file work?

I'm using window.location for internal redirects in a phonegap application okay.

Remy Sharp

unread,
Aug 24, 2012, 3:22:11 PM8/24/12
to phon...@googlegroups.com, phon...@googlegroups.com
I've not tested pre-existing files (you mean in the www directory?)

It's because I'm generating an .html file on the fly, and need to navigate to that. 

Any ideas on that front?

John Wards

unread,
Aug 24, 2012, 4:02:22 PM8/24/12
to phon...@googlegroups.com
I'm only suggesting checking window.location is working as I had great
trouble getting redirects working to local pre-existing files in www.

Just had a look at the source and it seems I changed from
document.location to window.location to get that to work so that might
not be much help after all! However it might be good to check
window.location is working because my experience with WP development
seems that things randomly don't work for no good reason ;)

Jesse

unread,
Aug 24, 2012, 7:48:28 PM8/24/12
to phon...@googlegroups.com
In WP7 the File root is physically located up one directory from the www folder.
You should be able to load your file via ../NewFile.html 

As an alternative, you may also resolve the url yourself in JS by dropping the "/www/index.html" from window.location.

Cheers,
  Jesse
@purplecabbage

Remy Sharp

unread,
Aug 25, 2012, 4:26:03 AM8/25/12
to phon...@googlegroups.com
Sadly none of that works.  I need to test the iframe solution, but my gut says it'll end up in the same situation.

Problem is, I'm not sure if this is a bug in the PhoneGap WP implementation or if it's a limitation of the device.  Again, what I'm doing is generating a file called "page.html", and trying to navigate to it.

Here's the errors in Visual Studio:

GapBrowser_NavigationFailed :: /app/page.html 
A first chance exception of type 'System.SystemException' occurred in Microsoft.Phone.Interop.dll 
ERROR: Exception in InvokeScriptCallback :: An unknown error has occurred. Error: 800A1393. 
A first chance exception of type 'System.SystemException' occurred in Microsoft.Phone.Interop.dll 
ERROR: Exception in InvokeScriptCallback :: An unknown error has occurred. Error: 80020006.

And the exception on the phone is (obviously line 1 not actually being the line):

Origin Error:: Unspecified error in x-wmapp:/app/www/index.html at line 1

 Thanks for the advice so far!

Jesse

unread,
Aug 29, 2012, 9:37:44 PM8/29/12
to phon...@googlegroups.com
Hi Remy,
Do you have a quick sample tidbit to reproduce the issue, to save me a couple minutes?

Cheers,
  Jesse

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
 
 



--
@purplecabbage

Reply all
Reply to author
Forward
0 new messages