Button Navigation in Windows 8 App - javascript

I am really new to Windows 8 App Development.I am creating a Windows 8 App in which I need to click a button and open another page. I am developing this windows app using HTML/CSS and Javascript. How can I navigate to another page using a button click? I have tried several with window.ways which I can use with HTML/Javascript for Browser web pages. But non of them are working. Is there a special way to do this in Windows 8 App development? Can anybody please explain with an example.
Thank you.

I could guess that maybe your problem is in understanding the different contexts? A page can run in the "local context" which gives it the permissions of your app and access to the Windows 8 API. A page can instead be run in the "web context" in this context it does not have access to the Windows 8 API but can execute remote code.
Basically, you start in the local context...code that is part of your app. From there, you can link to pages in your app's package (these would run in the local context). You could also link to things outside of your app package (these things would run in the web context). The confusing thing is when you link to something in the web context. Basically, since replacing the current page/screen with the web-context would make you lose all access to the Windows 8 API, when you link to something in the web context, Windows 8 won't replace the screen with that page, instead it will open up IE10 and load the page in there; That way you don't lose control of your app. The trick to loading stuff in the web context is to load it in an iframe which is in the web context. But you always need to keep the main page itself in the local/app context.
For your reference:
Urls starting in "ms-appx:///" load in the local context.
Urls starting in "ms-appx-web:///", "http://" or "https://" load in the web context.
As far as I remember, if unspecified, links are in the same context as the page they are in.
In terms of how to do it...you should be able to use <a href="..."> as well as the usual javascript ways. It's been a while since I've coded for Windows 8, but I don't remember that part being different from how I did things in normal web development.
Unless of course you are talking about the PageControl object or the navigation template. So many things. Either way, I strongly recommended getting the free book "Programming Windows 8 Apps with HTML, CSS and Javascript" by Kraig Brockschmidt. It's an easy read full of examples and I'm sure that will solve 99% of your questions if you are new to this.

So you tried the
href="____.html"
try dropping the ".html" so it is just
href="____"
And do you have the controller to handle it when you tell it to go the page?

Related

Google Analytics: Do I need URL address?

I am a complete Google Analytics beginner and would appreciate a help with a basic question.
I am developing HTML, CSS and JavaScript based applications which are further uploaded into an iOS application to present your applications in a fancy way. Therefore my application is a hybrid application (half JS web site, half mobile app).
I would love to see users' activity in my app when they are browsing through it and I thought GA might work well with it - but the problem is, that the outer app doesn't provide me with any URL of my inner JS app (the inner web site's URL is file:///).
At this page (link), I found that URL is not really important, that it is the tracking code which is important. So I used a dummy URL, added the GA snippet into my application and uploaded it in iPresent. I can't see no live activity though... :/ It also says the measuring is not installed (not used at a home page).
So I am wondering - is the URL really important?
Any ideas?
Thanks!
URL (or page path) is only important if you want to report on data based on which URLs your visitors went to.
If you app doesn't use URLs at all, perhaps it fits better with the "app" model where you are sending screen name data instead of page data. You can read more about the differences between web and app views here:
https://support.google.com/analytics/answer/2649553
I found out that URL is not needed. This type of problem can be solved by using GA Measurement Tool
https://developers.google.com/analytics/devguides/collection/protocol/v1/
Validate your hit here:
https://ga-dev-tools.appspot.com/hit-builder/

Getting camera and geolocation permission ahead of time

I'm building a web-app that uses the device's camera and location services. The browser (I'm sticking to Chrome for now) asks the user for permission to do so on the page where the service is used.
I want the interface to be able to ask for permission at an early stage in the workflow so the pop-up dialogs don't come up during the use of the app. I know they would go away after the first visit to a page, but I want to avoid it the first time too.
Javascript is pretty much the only tool I know how to use, and I know each page has a separate Javascript execution context, so I can't get references to the objects on one page and hand them over to another.
So is there a way that will work? Maybe I need to learn some other technology?
If you need to do it in the browser, then I would suggest creating a sort of initialization page before going to the actual app page.
In the ini page you can call all permissions and download+cache all needed app scripts and also validate which permissions were accepted and not. Kinda something like when using GMail you go through their ini page first before getting to the actual GMail ui.
Once the ini page has completely loaded simply redirect to the actual app.
If you want to do it outside the browser and still use the same web technologies, take a look at Electron or NW.js.
Both tools above lets you build cross platform desktop apps with web technologies. Things like asking for camera and geolocation can be done without user permission (as I recall. not sure)

How to detect URL scheme and prevent the default navigation to that URL in phonegap hybrid application

I have the following requirement for my application (Android, iOS):
When the application launches it displays a login.html page (which is part of the application). After logging in, the application's webview should be occupied with home.jsp from an external domain. When user clicks on logout button in home.jsp it has to navigate back to login page . On click of logout when we usewindow.location.href="login.html" then it tries to find the page on xxx domain.
Is there a way to detect this navigation URL and override the URL from javascript or phonegap properties in the application?
When I inspect window.location.href in an android emulator I get file:///android_asset/www/index.html
But I think Nathans idea of moving it to the server is a good one. You could also have one on the device if you really need to. (PErhaps you should ask the person specifiying the app achitecture how they would do it :) )
The answer is going to vary depending on how you've implemented the mentioned WebView where home.jsp is being displayed in. You did not provide any code or any specific information so the answer is going to be the same - somewhat vague...
If you've opened a new WebView, then you can't control it from JavaScript. You'll need to control it via Java or Objective-C code (you did not mention which environment you're developing for...).
For example, if you'll look in the your-app\android\native\src\com\your-app\your-app.java file, you'll see how the native layer loads the application's index.html file after the Worklight JavaScript framework has been loaded.
Similarly, you could re-use this approach in your own application to close and re-load login.html.
If you're in fact doing the mentioned re-direct from the comments, meaning you're re-using the current webview but replacing its content with external content, then I think it is expected that you've lost the context of the application, and when looking for login.html - it doesn't find it... because you've moved from app-context to web-context. They do not know each other.
I think you should not do this re-direct. Instead, you need to open a new WebView using a Cordova plug-in, and in this new WebView to display your external content.
In this Overlayed WebView, you can detect any urls that are clicked on and if the sign-out URL was detected, then close the WebView.
You can see parts of this in action in the Integrating server-generated pages in hybrid applications tutorial and accompanying sample project.
In the sample project, you can see the functions provided (where you can add yours) in android\nativeResources\src\com\IncludeExternalPages\IncludeExternalPages.java.

"Silently" invoke helper application using Javascript

Can Javascript cause browsers generally (and Chrome for Mac in particular) to invoke an external helper application for a URI without opening a new tab/window, or navigating away from the current page?
The context is that I am developing an extension for Chrome that occasionally needs to invoke particular actions outside of the browser. Using the rather neat trick described here, the extension only need open particular URIs to invoke suitable AppleScript.
However, how should one open such URIs from a script running in an extension's background page? I don't think XMLHttpRequest will help, as Chrome won't (shouldn't?) attempt to use an external helper application for XHR; nor does it appear that setting window.location.href has any effect on such a background page (it is not a problem if the background page is unloaded).
My current solution is to open a new window, but it's unnecessary and rather distracting for the user.
There are a few options here:
You could write an NPAPI plugin.
You can use a WebSocket client in the browser, and run a local server on your desktop. That way you establish a tunnel to your local machine to do pretty much anything you want there.
I did this for relaying global media key presses to control web-based music players and wrote it up. Source here.
I just realised I can do this with an <iframe/> in the background page. Très simple!

how can I launch/pass a value to a Windows C# application from a web page? (it seems possible with song links to iTunes)?

I'm putting together a C# winforms application, and it would be good to be able to have the ability for someone to click on a webpage link that automatically maximizes my c# application and passes some data to it. Pretty much like I see some webpages have a song link that automatically opens iTunes, and then in iTunes it searches for the song details you passed.
Q1 - How does one do this in HTML/Javascript?
Q2 - Does this approach only work on certain browsers?
Q3 - Would this only work on Windows? (I just need it for windows myself)
Thanks
You can register a URL protocol handler (see) which allows you specify a unique URL protocol and you can make clickable links in web pages which will spawn a new application passing the complete URL. Be careful though because this mechanism has been mis-implemented a number of times which can expose you to exploitation.
Also browsers will normally warn you if you are trying to use one of these odd URLs. And this will only work on Windows (but there are alternatives on other OSes).
You would have to associate a new file type with your C# application. The web page could "launch" such a file by downloading it.
I believe you'd have to pass parameters by writing them to the file to be downloaded.
It's true that there would be a "run or save" prompt, but aside from that, I think this would be the simplest method, and the one that would be easiest to maintain.
My first reaction would be that you'd have to create some kind of browser plugin first, that would act as the middle man between your javascript and your C# application. This is because website javascript and other code is run in a limited security context and cannot access priviliged resources, such as other applications, named pipes, tcp ports, etc.

Categories

Resources