Enabling Geolocation for localhost in chrome - javascript

I am pretty new to Javascript/html5. I am basically working off code provided in Rbon Nixon's book (4th Edition, Learning PHP, MySQL and Javascript...). Example 22-2 of which is about "displaying the map at a user's location".
I am getting caught in the if part of the following code snippet:
<script>
if (typeof navigator.Geolocation=='undefined')
alert("Geolocation not supported.")
</script>
Superficially, it seems quite obvious that I should enable geolocation int eh browser for localhost. I am using chrome (Version 60.0.3112.113). But when I go to Settings >> Advanced >> Content Settings >> Location
the ask before accessing option is enabled. and then there are the Block and Allow sections. But it does not give me an option to add localhost. How do I enable it so that I can use geolocation in my code and test it on my machine?

Related

Google authentication isn't working in Microsoft Edge

When clicking on the Continue With Google button, a popup appears (on my website that I created using Django in Python) as expected in Google Chrome asking which account to continue with etc...
By doing the same thing in Microsoft Edge, the popup is blank, there is no content. I'm not sure if it's a problem with my code, my OAUTH account or Microsoft Edge itself.
This is the popup in Google Chrome (working as normally)
This is the popup in Microsoft Edge (not working at all)
I expect the top image to be happening in both browsers.
Does anyone have any idea why this isn't working in Microsoft Edge?
EDIT:
The following two errors appear in the Microsoft Edge console but they also show up in Google Chrome:
Failed to load resource: the server responded with a status of 400 ()
[GSI_LOGGER]: The given origin is not allowed for the given client ID.
I tested the website in Firefox and everything works as expected similar to Google Chrome.
Why is Edge the only browser that isn't working (My Microsoft Edge is up to date)
HTML Code:
<script src="https://accounts.google.com/gsi/client" async defer></script>
<div id="g_id_onload"
data-client_id="**********.apps.googleusercontent.com"
data-login_uri="http://localhost:8000/accounts/continue-with-google/?source=signup"
data-auto_prompt="false">
</div>
<div id="continueWithGoogleButton" class="g_id_signin"
data-type="standard"
data-size="large"
data-theme="outline"
data-text="continue_with"
data-shape="pill"
data-logo_alignment="left"
data-width="300">
</div>
Be sure to read this, because it seems that might be causing the issue (blank window). Also, the key points are important (#2, and #3), since you're developing in localhost. This would also mean that you might need to add (if you don't have it already) a meta tag regarding the referrer policy.
This was answered in the comments by FiddlingAway. I wanted to post this as an answer to make it clearer for future references. To save a bit of research, in Django, you'll need to write in settings.py file SECURE_CROSS_ORIGIN_OPENER_POLICY = "same-origin-allow-popups". Check the above links to find out what this means.
Hope this helps!

Start TOMTOM navigation using Javascript and Android Intent

I have a web application that needs to open a destination in the native maps/navigation app on the device. On most Android devices this is google maps, and I can simply open a link that will open google maps with the directions to the passed destination (latitude, longitude coordinates). In the case of the TomTom Pro 8375, there seems to be no way of opening a destination in the navigator app from the browser.
We have tried this, amongst others, with the following:
tomtomgo://x-callback-url/navigate?destination=52.371183,4.892504
tomtomhome://geo:action=navigateto&lat=mylat&long=mylon&name=myname
Are there any known workarounds to achieve this?
I have received this as a response from the support but this applies only for kotlin or java.
Uri gmmIntentUri = Uri.parse("google.navigation:q=52.0000,12.0000");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
startActivity(mapIntent)
Is there a way that I can make this work in Javascript ?
I would really appreciate any suggestions!
Thank you!
Too Long to be a comment
Not overly familiar with webapps however we do have 3 apps with Webfleet. Sadly we use Java not Javascript. And the intent we use is
String uri = "geo:0,0?q=" + <destination>;
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(uri)));
Not overly helpful for you however we must support both phones and the Pro tablets.
The format below is the standard for JavaScript ?
intent:
HOST/URI-path // Optional host
#Intent;
package=[string];
action=[string];
category=[string];
component=[string];
scheme=[string];
end;
Which i would give you a rough estimate of:
intent://#Intent;action=android.intent.action.PICK;type=text/plain;S.android.intent.extra.TEXT=geo:0,0?q=52.0000,12.0000;end
I will also add the App that is Webfleets version of maps is called NavPadNavAppActivity, can try targeting that directly?

Issue migrating from GA to GTAG on ionic/cordova web app

Description
Since old GA SDK is getting obsolete, we are migrating to GTAG.
While migrating, I found this line :
ga('set', 'checkProtocolTask', null);
which disables the protocol check so that GA script works in a webview (where cordova uses the file:// protocol apparently)
What I've tried
I looked through the internet (about 2-3 pages of "similar but not quite the same" problems)
Only solution I found is there : https://support.google.com/analytics/answer/7475953?hl=uk
TLDR : add a script in Google Tag Manager, which will disable the protocol check for all trackers in google analytics and use that script in Google Analytics setup.
But :
* we are not using Google Tag Manager as of now, so we'd have to set the thing up just for that.
* it seems like a dirty hack to me... But it's not better than the old version I guess...
* I don't think it's good to have this piece of code in Tag Manager, when everything else is in GIT repo.
* It means we are disabling the protocol check, wherever it is called. Whereas the "hack" we had only disabled the protocol check when building the mobile app (desktop web was working without this line)
Is there no other solutions ? am I wrong ?
So... I just realised that using global site tag just uses ga as we used to.
So I actually ended up using the solution from the page I found : https://support.google.com/analytics/answer/7475953?hl=uk
Only I used that code snippet in my page instead of in a GTM variable.
So whenever I load my page, I do
ga(function() {
var trackers = $window.ga.getAll();
trackers.forEach(function(tracker) {
tracker.set('checkProtocolTask', null);
});
});
I wrapped the snippet in a function() {...}, that way it is apparently run after ga is initialized.
For Google Analytics 4 this feature is not yet implemented. So you cant disable protocol check. see the status here https://issuetracker.google.com/issues/174954288?pli=1

SharePoint & JavaScript - The "Open with Explorer" issue

This is a JavaScript/SharePoint issue. I have a similar question in the SharePoint StackExchange community but I haven't got anything over there in months. This particular issue is related to SharePoint 2010.
To the ones not aware, there is standard a functionality in SharePoint that allows users to open Document Libraries with Windows Explorer, which is very handy when you want to upload lots of documents or move file/folders around.
When the user clicks a button called "Open with Explorer", most of the time, the folder opens in Windows. Common answers like "Try restarting WebClient service" will not work, once users do not have permissions to do almost anything in their work PC's.
After researching the SharePoint JavaScript files I found how this functionality is supposed to work:
After clicking the "Open with Explorer" button, some functions will be called, but here is where the "magic" should happen:
function NavigateHttpFolderCore() {
httpFolderDiv = document.createElement("DIV");
...
document.body.appendChild(httpFolderDiv);
httpFolderDiv.onreadystatechange = NavigateHttpFolderCore;
httpFolderDiv.addBehavior("#default#httpFolder");
d = httpFolderDiv.navigateFrame("https://sharepointsite.com/sites/site1/docLib", "_blank");
if(d == "OK"){
...
}
...
}
From above:
addBehavior - not supported by IE 11, Chrome and Firefox, only IE 10 and older. If using IE 11, the <meta http-equiv="X-UA-Compatible" content="IE=8"> will take care of it.
#default#httpFolder - a behaviour(?), apparently not used anymore nowadays (obsolete)
navigateFrame - this either return the string "OK" if successful, meaning that the "Open With Explorer" will indeed Open in Windows Explorer, or it returns the string "FAILED" and the "your client does not support opening this list with windows explorer" will popup in my screen.
My main concern is, why sometimes navigateFrame return "OK" and other times "FAILED"?
Does anyone know what happens "inside" navigateFrame or can I check it? Any ideas?
Thank you
In my case the problem was in IE which blocked navigateFrame() call due to CORS restrictions. I dealt with SharePoint 2013 and provider-hosted add-in: I tried to open WebDAV folder (having the URL containing SharePoint host domain) with JavaScript from a PHAI web application in another domain -- PHAI domain. If you've got this problem in IE (version up to 10 inclusively) and you try to run your JavaScript code in a domain different from SharePoint one, try to add your site to 'Trusted Sites' and set 'Access data sources across domains' to 'Disable' or 'Prompt'.
Excerpt from MSDN :
Behaviors are subject to cross-frame security rules where a document cannot refer to a behavior on another server or another domain. In this case, the addBehavior method returns E_ACCESSDENIED. For more information, see the Security section in the Introduction to DHTML Behaviors article.

Google maps v3.19 won't load using embedded VB6 browser

We have a legacy VB6 application which until 17/2/2014 was loading and displaying maps using the Google maps V3 API perfectly. This was achieved by creating an html file and loading it using the VB6 browser ocx control. Now the maps won't load and the following error appears.
"Error: Could not get the display property. Invalid argument."
Opening the generated htm file using Explorer or Chrome works without any problems.
Ran into the same problem today with a c# app which has the windows forms webbrowser control
Got the maps working by changing the api call from
"https://maps.googleapis.com/maps/api/js?v=3.exp"
to
"https://maps.googleapis.com/maps/api/js?v=3.19">
Change your reference to the API to be:
<script src="https://maps.googleapis.com/maps/api/js?v=3"></script>
and it will fix it because this is a default reference to the release version (which is 3.19) that works.
3.20 - The experimental does not work.
after more research: According to this link : https://code.google.com/p/gmaps-api-issues/wiki/JavascriptMapsAPIv3Changelog, all calls to 3.17 will serve 3.18. excerpt below:
3.20 17 February 2015
The current JavaScript Maps API v3 experimental version (3.19) will become the release version.
Version 3.17 will be removed. Requests for 3.17 or any prior version will now be served version 3.18.
Versioning documentation is available at: https://developers.google.com/maps/documentation/javascript/basics#Versioning
Available versions after rollover:
Experimental: 3.20
Release: 3.19
Frozen: 3.18
Adding
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" >
directly under the head tag in the web page the browser is displaying worked for me if you still have access to that.
We had this same an issue with powerbuilder with embedded browser ..
Here's how to fix .. use regedit goto key as visible on bottom of image, you will see key. create a reg_dword and name it to you application (ours is tpdesp.exe) The data of 8000 says to use IE8 (which almost all of our customers have). You can set this to 9000 or 10000, use google to get explanations of this.
notes : The app we had the issues with is a 32 bit app running on windows7 64. If that's not what you have search the registry for feature_browser_emulation and fix it there.
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION]
It's working (Windows Forms C# in WebControl)
Only adding: v=3.19
public static string llamadaMapas = "<script type=\"text/javascript\" src=\"https://maps.google.com/maps/api/js?**v=3.19**&sensor=false\"></script>";
This fixed a similar problem with GeoSetter. (Map not working.) I had to search in the registry for the feature_browser_emulation key area to be added to, but Geosetter now works. (Just added the key and restarted the program.)
Thank you.

Categories