Can we enable browser location using jquery - javascript

How can I automatically enable browser location using jQuery? Currently I can detect whether location is enabled or not from the code written below:
setInterval(function () {
navigator.geolocation.getCurrentPosition(positionFound, positionNotFound);
}, 6000);
function positionFound() {
return true;
}
function positionNotFound() {
var template = site_url + 'front/auth/setLocationFancybox';
if (!$('.fancybox-overlay').html()) {
$.fancybox.open({
padding: 0,
href: template,
type: 'iframe',
'closeBtn': false
});
}
}
In the fancybox there will be two buttons:
Turn on location: By which browser location will be turned on.
Cancel: By which current parent window will get closed from the fancybox.
How can I turn on browser location and how can I close parent window from fancybox?

It is not possible to turn on browser location using JavaScript/jQuery. Users need to grant permissions in their preferences. Your best option there is to specifically ask your users to enable it.
To close the parent window from fancybox you can use the following line of code:
parent.$.fn.fancybox.close();

Related

Programmatically (or optionally) override Chrome's New Tab page

I've written a Chrome extension that overrides the New Tab page:
manifest.json:
"chrome_url_overrides": {
"newtab": "new-tab.html"
},
Is there a way to make this override optional? That is, I'd like to enable the user to uncheck a checkbox in the options page and disable the New Tab override. This must be possible because when I open a new tab for the first time, there's a popup informing of an extension changing the New Tab settings and asking whether to keep changes or restore settings:
I couldn't find any API for controlling overrides. The New Tab Redirect project doesn't have an option to display the native New Tab.
Google made a Star Wars new tab replacement which allows you to view the default new tab page. The url it uses is chrome-search://local-ntp/local-ntp.html.
Example:
options.html:
<input type="checkbox"> Use default new tab page
options.js:
var checkbox = document.querySelector("input[type=checkbox]")
checkbox.addEventListener("click", function() {
chrome.storage.sync.set({ defaultnewtab: checkbox.checked })
})
newtab.js:
chrome.storage.sync.get("defaultnewtab", function(storage) {
if(storage.defaultnewtab) {
chrome.tabs.update({ url: "chrome-search://local-ntp/local-ntp.html" })
}
})
Instead of using the chrome_url_override you could write a listener that listens for when tabs update using the chrome.tabs.onUpdated.addListener(), then check if the url is chrome://newtab/ and if it is and the check box is ticked, then using chrome.tabs.update() relocate them to another page.
Using the Star Wars method as described #Daniel Herr, I did this, which is working well. Although feels a little hack-y.
I have an option being set in the popup.html whether the Extension is "on" or not.
First off, set the default new tab page using the Chrome defined method:
manifest.json
"chrome_url_overrides": {
"newtab": "newtab.html"
},
Then in your Extension's newtab.html call a new JavaScript file, newtab.js (or whatever).
I am also using jQuery, so my code uses that, but you can do this natively using DOMContentLoaded.
newtab.js
$(document).ready(function(){
// It takes a moment for the Chrome query/update so sometimes there is a flash of content
// Hiding the Body makes it look blank/white until either redirected or shown
$('body').hide();
var background = chrome.extension.getBackgroundPage();
var _app = background._app;
// App is OFF, show Default New Tab
if(!_app._on){
// Get the current Tab
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
var active = tabs[0].id;
// Set the URL to the Local-NTP (New Tab Page)
chrome.tabs.update(active, { url: "chrome-search://local-ntp/local-ntp.html" }, function() { });
});
// App is ON, show custom content
} else {
$('body').show();
}
});
Basically, the methodology is to update the Tab so that it is redirected to chrome-search://local-ntp/local-ntp.html which is the hard URL to the default Chrome NTP.
Since this is a Chrome internal URL -- the URL field still appears blank.

Firefox extension open an HTML options page

I have an options page for my extension that is made with HTML and javascript tio be activated when options are selected. The extension is a window that hovers over the web page, and it has an "Options" button in it already.
I need to have the options page be opened in a separate tab in the browser when the button is clicked.
What I have so far is:
mainPanel.port.on("options", function () {
currentUser=null;
mainPanel.hide();
var url = serverURL+"/options.html";
tabs.open(url);
});
options.html is stored in the main file for the extension, and serverURL refers to the main server that the extension contacts for information.
In this case you need to use Port.on()/Port.emit() to send a controll option from options.html, like click on setting button.
options.html
var panelIsOpen = 0;
$('#settings').click(function() {
self.port.emit("statusoptions", {optionsIsOpen:1});
});
popup.html
Panel.port.on("statusoptions", function (panda) {
if(panda.optionsIsOpen === 1){
Panel.hide();
tabs.open({
url: "options.html",
onReady: function onReady(tab) {
Panel.hide();
},
contentScriptFile: [
data.url("js/jquery-2.0.0.min.js"),
data.url("js/options.js")],
});
}
});

How to handle links that open _blank windows in node-webkit properly?

I'm trying to use new-win-policy event to handle link clicks that open new windows. https://github.com/rogerwang/node-webkit/wiki/Window#new-win-policy
win.on('new-win-policy', newWinPolicyHandler);
function newWinPolicyHandler(frame, url, policy) {
gui.Window.open(url, {
position: 'center',
frame: true,
toolbar: true,
focus: true
});
policy.ignore();
}
After click on a link the handler isn't called. I got the message in console:
[17120:1029/214512:INFO:CONSOLE(138)] ""Remove zombie callback for window id 1 ev: new-win-policy"", source: window_bindings.js (138)
Have no idea what to do...
Thanks very much for posting your question. Info on doing this seems scarce. I was able to try out some variations based upon your sample. In my case I'm using an iFrame in NWJS, and was able to prevent popups, forcing the URL into the iFrame:
win.on('new-win-policy', newWinPolicyHandler);
function newWinPolicyHandler(frame, url, policy) {
policy.ignore(); //ignore policy first to prevent popup
$("#Your-iFrameID").attr("src",url); //load popup url into iFrame
}

Addon SDK. How I can make popup like this?

It's possible to made popup like this?
Not contents in it. The style and position of popuping is interesting for me.
Under toolbutton, with arrow up to center of button.
The panel widget didn't do the same, it just popup in center of window.
How I can do this popup with Add-on SDK?
On Firefox 30 and above, you can attach a Panel to a ToggleButton like this:
var panel = require("sdk/panel").Panel({
...
onHide: function(){
button.state('window', {checked: false});
}
});
var button = require("sdk/ui").ToggleButton({
...
onClick: function(state) {
if (state.checked) {
panel.show({
position: button
});
}
}
});
Specify where to attach the panel via position parameter in call to Panel.show; In this case, we're attaching it to the ToggleButton.
more information: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/panel#Attaching_panels_to_buttons
The panel API lets you create basic panels using HTML5 (+ Javascript and CSS, of course).
var panel = require("sdk/panel").Panel({
contentURL: require("sdk/self").data.url("myFile.html")
});
panel.show();
Then there are Australis "View" panels, which are XUL-based and integrate better with the Australis customization API, e.g. it looks more Firefox-"native" and the "Views" are properly integrated when a ancestor toolbar button in the "hamburger menu". There is no SDK abstraction available ATM.

addon firefox - open window with specific dimensions

I have made an addon for firefox. I install it but i have two problems.I use windows.open because the panel isn`t suitable for me because if the user want to copy something in it, the panel is disappearing when he leaves it. So i have windows. I have this code:
var widgets = require("sdk/widget");
var windows = require("sdk/windows").browserWindows;
var self = require("sdk/self");
var widget = widgets.Widget({
id: "open window",
label: "test",
contentURL: self.data.url("favicon.ico"),
onClick: function() {
windows.open({
url: "http://www.example.com",
onOpen: function(window) {
}
});
}
});
I don`t know where to put the attributes of width,height,no scroll :/ in order to be displayd as a popup window.
And the second problem is that the button is displayed at the bar of addons.How it is possible to display it at the nav bar next to firebug?
The windows module does not support specifying window features.
You could use the unstable window/utils module and the openDialog function to provides.
Or you could get yourself chrome privileges and re-implement the stuff yourself. The implementation of openDialog is surprisingly pretty straight forward and can be borrowed from easily.
Either way, you'll need to wait for a window to actually fully load (newWindow.addEventListener("load", ...)) before you can safely interact with it. Or get somewhat hackish and listen for the first open event via the windows module.

Categories