How can I prevent Firefox from asking the user to share their location every time it is requested?
I am using the Google map api. Below is my code to share the location. In Firefox it always asks to share location with the popup below. This happens every time, whether I click on Share or Not Now.
Below is my code
<% if (!Page.IsPostBack)
{ %>
// opened the share location
if (navigator.geolocation)
{
try
{
navigator.geolocation.getCurrentPosition(onPositionUpdate);
}
catch (err)
{
alert(err);
}
}
else
{
alert("You location is not available. Please enter your location to continue!");
}
<%}%>
function onPositionUpdate(position)
{
var lat = position.coords.latitude;
var lng = position.coords.longitude;
try
{
var latLng = new google.maps.LatLng(lat, lng);
if (marker == null)
{
alert("Sorry we are not able to update your location.");
}
else
{
setTimeout(function ()
{
marker.setPosition(latLng);
map.setCenter(latLng);
document.getElementById('ctl00_ContentPlaceHolderBody_latSel').value = lat;
document.getElementById('ctl00_ContentPlaceHolderBody_lngSel').value = lng;
geocodePosition(latLng);
}, 100);
}
}
catch (err)
{
alert(err);
}
}
This happens because you're using navigator.geolocation.getCurrentPosition.
Browsers have to ask users permission for sharing your geolocation. It depends of the settings of your browser. If you want to always share your geolocation, in firefox, just follow this link and go to the last paragraph.
Location-Aware Browsing is always opt-in in Firefox. No location information is ever sent without your permission. If you wish to disable the feature completely, please follow this set of steps:
In the URL bar, type about:config
Type geo.enabled
Double click on the geo.enabled preference
Location-Aware Browsing is now disabled
Most likely because your port number changes when you run your website on development server. Goto project properties -> Web -> Servers section: and set Specific Port instead of Auto-assign.
Because by default setting with webkit and opera browser's normally. For iOS it is necessary to use html5 with -webkit keyword in css some functions doesn't works in other browsers. Basically safari, chrome, opera is used in mobile devices and device features works fine with these.
Firefox browser is not a better option for mobile devices.
Related
I'm automating a windows based desktop application(C#, LeanFT).
Clicking on a button, opens a web page in the browser.
How can I verify the web page is opened?
Two ways:
Brute force
By describing the browser that was opened, which has a title, a url and other attributes, and then attaching to it.
The problem with this approach is that, if the browser was not opened, it will throw an error, so you'll have to try..catch that error
For example:
/*
* Desktop related logic that opens a browser
*/
// Use "Attach" to connect a new (or replacement) browser tab with the LeanFT test.
try {
IBrowser yourPage = BrowserFactory.Attach(new BrowserDescription
{
Title = "The title of the page",
Url = "https://thesitethatwasopened.com"
});
} catch (Exception ex) {
// the browser was not opened
}
/*
* Rest of the desktop app actions
*/
Iterating over all opened browsers
You'd still need the same description, but this way you can either get no browsers at all, which means that the page was not opened, or one or more browsers - in either case, this doesn't throw an error, so you can call it a "cleaner" way:
For example:
/*
* Desktop related logic that opens a browser
*/
// Use "GetAllOpenBrowsers" to get a collection of IBrowser instances that matches the description
IBrowser[] yourPages = BrowserFactory. GetAllOpenBrowsers(new BrowserDescription
{
Title = "The title of the page",
Url = "https://thesitethatwasopened.com"
});
/*
* Rest of the desktop app actions (maybe by making use of yourPages.Count
*/
I have a requirement to track how much time the user spending time on web sites/web application. Its like a time tracking tool for websites, I have wpf application which will open the websites on IE/Chrome/Firefox. I need to track the how much time user works on the website.
Chrome and firefox provides the history which i can get from sqlite database that stores in the user system but IE doesn't provide any information about the history.
Is there a better way i can track all browser activity with the user spending time on each websites?
I have wpf application which will open the websites on
IE/Chrome/Firefox. I need to track the how much time user works on the
website
It's a very important Feature Request by many for web 2.0 applications. So, I write a detailed, working and simple solution on the subject here.
You are requesting a feature already created for this workflow. It's a plugin you can include in any website. It's none other than time-on-site tracking in timeonsite.js
Look at the following code (Use latest version; don't just copy/paste),
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/timeonsite/1.2.0/timeonsitetracker.js"></script>
<script>
var config = {
// track page by seconds. Default tracking is by milliseconds
trackBy: 'seconds',
trackHistoryChange: true, //Single-page React/Angular app
callback: function(data) { /* callback denotes your data tracking is real-time */
console.log(data);
var endPointUrl = 'http://example.com' //Replace with your actual backend API URL http://localhost/tos
if (data && data.trackingType) {
if (data.trackingType == 'tos') {
if (Tos.verifyData(data) != 'valid') {
console.log('Data abolished!');
return;
}
}
// make use of sendBeacon if this API is supported by your browser.
if (navigator && typeof navigator.sendBeacon === 'function') {
data.trasferredWith = 'sendBeacon';
var blob = new Blob([JSON.stringify(data)], {type : 'application/json'});
navigator.sendBeacon(endPointUrl, blob);
}
}
}
};
var Tos;
if (TimeOnSiteTracker) {
Tos = new TimeOnSiteTracker(config);
}
</script>
</head>
Then, when you refresh, reload or navigate the React app page,
You'll see following object directly saved into your table/printed in browser console. Select "persist" in logs,
{
TOSId: 1129620185532,
TOSSessionKey: "14802525481391382263",
TOSUserId: "anonymous",
title: "Test application - Home page",
URL: "http://nature-blogs/pages/home.php"
entryTime: "2021-11-27 13:15:48.663",
currentTime: "2021-11-27 13:17:31.663",
timeOnPage: 103,
timeOnSite: 103,
timeOnPageTrackedBy: "second",
timeOnPageByDuration: "0d 00h 01m 43s",
timeOnSiteByDuration: "0d 00h 01m 43s",
trackingType: "tos",
}
As you can see, the actions
"entryTime" is captured
"exitTime" is captured in seconds/milliseconds depending upon configuration
"type:time_on_site" is captured
"timeOnPage" is captured // individual page time
"timeOnSite" is captured // session overall page time
What else you need? Since it's stored in SQL DB table, you can do analysis/reporting queries yourself. This works in any RDBMS DB smoothly.
On top of it, 1.Minimize tab, 2.Inactive tab and 3.Switch tab's idle time are all computed and ignored automatically by the tracker itself.
The only thing to note in configuration part is,
trackHistoryChange: true
If the page routing depends on Location Hash or also known as single-page app, include this setting. On the other hand if your web application is a normal page like Wikipedia, avoid setting this line. You are done. For showing the real-time stay time on screen, check this SO post. It's using Jquery to show the results. You can customize it for your React app.
This tracker can be plugged-in in any library VueJs, React, Angular, Jquery, MooTools etc. since it's plain vanilla JS library.
Let me know if you need more input on the subject. I can assist you on this.
I'm coding an iPhone app with a UIWebView, in Xamarin using C#.
By default embedded links within the web view open a web page in that same web view. I would instead like them to launch the linked page in a new safari browser instance.
This has been answered for objective C in X-Code but as far as I can see not for Xamarin C#
webView.LoadHtmlString(html, new NSUrl(Const.ContentDirectory, true));
Thanks in advance
Adam
You can open a web page in the brower of the device (Safari) with this command.
UIApplication.SharedApplication.OpenUrl(new NSUrl("www.google.com"));
You don't have to use UIWebView at all. If you want to open some web pages in UIWebView and some with Safari you need to implement the ShouldStartLoad delegate. Here you can determine whether to open the web page in UIWebView or rather in Safari.
private bool HandleShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
{
// you need to implement this method depending on your criteria
if (this.OpenInExternalBrowser(request))
{
// open in Safari
UIApplication.SharedApplication.OpenUrl(request.Url);
// return false so the UIWebView won't load the web page
return false;
}
// this.OpenInExternalBrowser(request) returned false -> let the UIWebView load the request
return true;
}
At last somewhere in ViewDidLoad (or other place where you initiliaze the WebView) add the following code.
webView.ShouldStartLoad = HandleShouldStartLoad;
If loading content into a UIWebView and you want to use Safari to open links, doing it the way described above will get you a blank page. You need to check the NavigationType.
private bool HandleShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navType)
{
if (navType == UIWebViewNavigationType.LinkClicked)
{
UIApplication.SharedApplication.OpenUrl(request.Url);
return false;
}
return true;
}
The easiest/simplest way to do it is to assign a delegate to the UIWebView's ShouldStartLoad property:
webView.ShouldStartLoad = (w, urlRequest, navigationType) => {
// Open the url in Safari here.
// The urlRequest parameter is of type NSUrlRequest, you can get the URL from it.
return false; //return true for urls you actually want your web view to load.
};
Make sure the delegate returns false, for the links you want to load in Safari, so that your UIWebView does not load the link.
I have a website, in which when user clicks a link it opens up in the same window if it is of my website's page, else in new window if domain is different. But I am doing this manually like this:
Open Link
checkdomain() checks the domain name of the link and returns true if it's of my website else false. I used the code from [ HERE ] for this purpose.
My question is: Is there any efficient and client side way available for checking link domains and open up them in new windows/tab if of another website(domain)? Like a JavaScript solution will be better, but then again JavaScript can be disabled by user. So, is there any other solution? Even JS solution will be great. Ignoring the disabling by user.
Somewhere on the page, or in an external JS file:
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href")
&& anchor.getAttribute("rel")
&& anchor.getAttribute("rel").indexOf("external") >= 0)
anchor.target = "_blank";
}
}
window.onload = function() {
externalLinks();
};
Then, any external links just need to have rel="external" in the markup. For example:
Click here!
The main advantages of this approach is that you're not going to cause any validation errors, even with an XHTML Strict doctype. Users are also able to easily prevent links opening in new windows by simply disabling JS.
If you need the decision of external/internal to be made automatically (and client-side), you can alter the logic of externalLinks to base the decision on the href attribute rather than the rel attribute. Of course, if you've already got the external/internal logic functioning in your codebehind, I would recommend using that information to render the anchor with the appropriate semantics (with rel), rather than re-writing almost identical code in your client-side JS.
Try comparing your link url's host part (www.wrangle.in) with following in you function logic.
string currentURL = HttpContext.Current.Request.Url.Host;
I do not recommend to compare the name (i.e http or https), you can split using substring function.
For Client side
var homeURL = document.location.hostname;
$('a').each(function() {
if ( $(this+'[href*='+homeURL+']')) {
$(this).attr('target','_self');
}else{
$(this).attr('target','_blank');
} });
This link may help you to understand Url Parts.
To need to login to a site, go to a particular page (eg. local router page) and click a button to do an operation(eg Connect). Since I do it almost everyday, I thought of automating it through small C# application. I don't have any idea how to do it.Any pointers?
Why code C# for one click? Try AutoIt.
Here is a starter tutorial. This will help you to quickly automate clicking on the default buttons of an application. Some more tricks from AutoIt and you will be able to do almost anything you can tell someone over the phone to do on the GUI.
AutoIt is a useful tool to keep handy if you are working with GUI testing or were dreaming of scripting a lot of routine GUI activity.
Capture the content of the HTTP-request using a tool like Fiddler. With this information you can build an application that executes these HTTP-requests.
Trace the HTTP requests your sending using
a browser plugin (Firebug, httpwatch, tamperdata, etc.)
a web debugging proxy (fiddler, charles, etc.)
a packet sniffer (wireshark, etc.)
And then use the classes in the System.Net namespace (e.g. WebClient) to execute the same requests.
You can also use the Selenium IDE, which is a FireFox plugin that allows you to record macro like scripts for playback in the browser. It is designed for automated testing of web pages, but you can export the script in C#, which can in turn be run from a console app.
If you plan to run it as a C# app, you will also need to look at Selenium RC.
Happy scripting :)
I have created app in C# which uses the WebBrowser control provided by Microsoft
and used it to ope a website and tried to manipulate it's html and tried to put values in
some text boxes and tried to hit the button it works for me ,hope it's helps for you as well
Sample code is as follow
internal void LoginToSite()
{
WebBrowser.Navigate("some site login Page");
_Processing = true;
var username = ConfigurationManager.AppSettings["username"];
var password = ConfigurationManager.AppSettings["password"];
while (_Processing)
{
Application.DoEvents();
if (WebBrowser.ReadyState == WebBrowserReadyState.Complete || WebBrowser.ReadyState == WebBrowserReadyState.Interactive)
{
var htmlDocument = this.WebBrowser.Document;
if (htmlDocument != null)
{
foreach (HtmlElement tag in htmlDocument.GetElementsByTagName("input"))
{
switch (tag.Name)
{
case "username":
tag.InnerText = username;
break;
case "password":
tag.InnerText = password;
break;
case "cmdlogin":
tag.RaiseEvent("onclick");
tag.InvokeMember("Click");
break;
}
}
}
_Processing = false;
}
}
}