Should javascript geolocation prompt user to turn on location services? - javascript

I am using the geolocation functionality to track user's locations with javascript. More specifically, I am using navigator.geolocation.watchPosition. My site works fine. When I visit my site on my Android device it prompts if I would like to allow the site to track my location. I tap allow (as well as remember my preference).
After success with that I turned off location services on my phone and went back to the site. It didn't prompt me for permission again (since I told it to remember my preference last time but it didn't prompt me to turn on my location services either. Needless to say at that point my site never got any geolocation data from the browser.
My question: Is there some way to prompt the user to turn on their location services programatically? If I had not saved my security preference and it prompted me to allow again would it have turned on or asked me to turn on location services? I would hate to have to tell the user they need to go into their cell phone's preferences to enable it.

It's browser specific or to be more exact - application specific. What you could do is wait e.g. half a minute or a minute for the location and if it is not available show a warning to the user.

Related

geolocation not working in mobile's browser Javascript

I'm currently developing a mobile web page integrated with google map, and I need to include a my location button on the google map. in JavaScript i having something like this
navigator.geolocation.getCurrentPosition()
It is working in desktop browser, prompt me whether allot website access my location. In mobile browser it doesn't prompt me allow or deny, just throwing error says "User denied Geolocation".
Does anyone has come across this?
So you'll have to allow location sharing on an iPhone.
Go to Settings > General, then go to Reset > Reset Location & Privacy.
If you intend this to be used by other users you'll have to prompt for permission like Justinas stated.

Is it at all possible to determine whether the running browser is the default browser in JavaScript?

It would be very useful, in my application, to know whether the current browser is the default browser.
Is is possible, using JavaScript, to know whether the browser my page is opened in is the default browser (i.e. the browser that would open if I were to click on a link in another app. like, for example, an email reader)?
Update
To answer E. Sundin and other possible readers, there is the main reason why I would like to know whether the current browser is the default browser:
When a user registers on one of my websites, I register the User-Agent as a token that should not change between the time the user registers and the time the user clicks on the email verification link. Unfortunately, when users click on the link, it opens in the default browser.
If I knew, I could do several things:
Not put a link in the email, just ask the user to copy/paste the token to his still open browser
Warn the user as he is registering that it won't work if he just follows the link (if I know that this browser is not the default.)
Eventually ignore that test (that could be an admin. setup, in most cases website owners do not care that much... so not having such a test would be similar to nearly all other websites. Reduced security, but since the majority does that anyway...)
Of course, it happens that people register on their smart phone, receive their email on their desktop and follow the link there. That would also not work well with such a test...
No, there is no Javascript API for this.
Keep in mind that not all operating systems even have the concept of a "default browser".

Set Javascript cookie from google location permission?

I have a feature on a site that gives the user the telephone number of their closest branch of shop based on their current location via the google-maps api.
When the page loads for the first time, the browser automatically asks the user if they would like to share their location. That's all fine, except some browsers don't handle it as well as others and continually ask the user when the move from page to page (the number is on every page).
So is there a way I can set a cookie based on weather or not they gave permission and only display the automatic 'this site would like to use your current location' message if the cookie has expired after say, a month?
It is particularly bad on smartphones, it asks all the time.
This is more of a browser related issue rather than a coding issue. In browsers like Chrome this interference in inevitable. It has to do a lot with security concern. Hackers can create a fake webpage for a banking site as a part of phishing and hack peoples password.
Most of the latest browsers disable hiding the location bar, although in some browsers, setting location=no will disable the address bar from being modified.
But from a coding perspective you have some options, Some of them are listed below.
You can use a localStrorage object that persists any saved data indefinitely on the user's computer and across browser tabs (similar to JavaScript cookies).
Here is a demo code:
<script type="text/javascript">
var mydomstorage=window.localStorage || (window.globalStorage?globalStorage[location.hostname] : null)
if (mydomstorage){
var i=(mydomstorage.pagecount)? parseInt(mydomstorage.pagecount)+1 : 1
document.write("You have visited this page <b>" + i + " </b> times altogether.")
mydomstorage.pagecount=i
}
else{
document.write("<b>Your browser doesn't support DOM Storage unfortunately.</b>")
}
</script>
This code works on FF3+, Chrome4+, Safari4+, Opera10.5+, or IE8+
If you have windows popping up that ask for the location you can try out this simple solution by making window.open=null; on the instance that is responsible for fetching out the location.

ASP.NET MVC 4/Web API Single Page App for Mobile Devices ... Needs Authentication

We have developed an ASP.NET MVC 4/Web API single page, mobile website (also using jQuery Mobile) that is intended to be accessed only from mobile devices (e.g., iPads, iPhones, Android tables and phones, etc.), not desktop browsers. This mobile website will be hosted internally, like an intranet site. However, since we’re accessing it from mobile devices, we can’t use Windows authentication. We still need to know which user (and their role) is logging in to the mobile website app.
We tried simply using ASP.NET’s forms authentication and membership provider, but couldn’t get it working exactly the way we wanted. What we need is for the user to be prompted for a user name and password only on the first time they access the site on their mobile device. After they enter a correct user name and password and have been authenticated once, each subsequent time they access the site they should just go right in. They shouldn’t have to re-enter their credentials (i.e., something needs to be saved locally to each device to identify the user after the first time).
This is where we had troubles. Everything worked as expected the first time. That is, the user was prompted to enter a user name and password, and, after doing that, was authenticated and allowed into the site. The problem is every time after the browser was closed on the mobile device, the device and user were not know and the user had to re-enter user name and password.
We tried lots of things too. We tried setting persistent cookies in JavaScript. No good. The cookies weren’t there to be read the second time. We tried manually setting persistent cookies from ASP.NET. No good. We, of course, used FormsAuthentication.SetAuthCookie(model.UserName, true); as part of the form authentication framework. No good. We tried using HTML5 local storage. No good. No matter what we tried, if the user was on a mobile device, they would have to log in every single time. (Note: we’ve tried on an iPad and iPhone running both iOS 5.1 and 6.0, with Safari configure to allow cookies, and we’ve tried on Android 2.3.4.)
Is there some trick to getting a scenario like this working?
Or, do we have to write some sort of custom authentication mechanism? If so, how? And, what?
Or, should we use something like claims-based authentication and WIF?
Or???
Any help is appreciated.
Thanks!
try adding .browser file as discussed here:
http://www.simonantony.net/knowledge-base/articles/browsing-your-site-on-an-iphone-using-chrome-does-not-work/
I know it says chrome, but i've accountered this problem with safari also.

Can I Create Chrome Application Shortcuts Programmatically from a Web Page?

I've thought about using Chrome and HTML5 local storage to create a useful app and sell it. The problem I think I would have, however, is the delivery mechanism to get this installed on one's computer. Let's say the app was wikipedia.com (although it isn't). Manually one can go there with Chrome, then choose the wrench icon, Tools, Create Application Shortcuts, and make a desktop and application menu icon for the app.
Okay, fine, but is there a way I can compose a web page link or form button such that it does this for me? In other words, one clicks a button or link and it shows the Create Application Shortcuts form. I am hoping that there's this little-known way on Google Chrome to use either HTML or Javascript to trigger showing that form.
As for those who don't have Chrome, I can detect that and give them a button they click that emails them. In the email, it will give them instructions for installing Chrome and then another link so that they can visit this page in Chrome in order to get the button that shows the Create Application Shortcuts form.
For now, until a better answer can be provided, this is sort of the technique for deploying a desktop app with Chrome, the manual way, and without having to register in the Chrome Store:
After the user purchases a product, email them the serial number for registering their product and a web URL to install this new product.
The web URL is the actual URL of the web app. However, it doesn't display its normal content by default. Instead, the web app is in "installer mode". It does this by looking at a 200 year persistent, encrypted, registration cookie that may not already be installed. (Note if they delete cookies, there's no harm done -- it just asks them to re-register again.)
The first thing the web app does in Installer Mode is detect user agent. If it finds this is not Chrome, it gives them a link to install Chrome and tells them to follow the instruction email again that they have already been sent, but using Chrome to do this. (You might also want to provide a form to resend them the instructions and serial number again.)
The user either installs Chrome and returns back to this page again, or is already a Chrome user. The Installer Mode then shows a message that reads, please press the ALT-F key in Chrome, or press the Wrench icon in your toolbar, and choose Tools > Create Application Shortcuts, check the two checkboxes, click OK, and then click the "Task Performed" button below.
The user follows the instructions and creates their desktop/application shortcut and then clicks "Task Performed".
The user then sees a registration form where they are to type in their serial number they were emailed. The user enters this in and clicks the Register button.
The server validates the registration and then stores a persistent, 200 year encrypted cookie that basically says, "This guy is registered." This keeps the web app from running in Installer Mode.
The Installer Mode is still active, however, and shows them the final prompt: "You may close your browser and run the icon for the new app from your desktop or application shortcut that you created. The icon is named '{insert name here}'."
They close their browser and doubleclick the icon. The application loads, the registration cookie is read, and the web app no longer runs in Installer Mode -- it shows the application content like it normally would. Besides the fact that this is not a 100% truly automated install, the only drawback is that, since the main page is not a local file (cached), the web app can't really work offline completely. Sure, it can use HTML5 offline storage, but doubleclicking the desktop shortcut will always connect to your web app site.

Categories

Resources