I have a browser action button. When the button is clicked, I need to do some computation and decide which window to open.
If I set default_popup in manifest.json, the popup looks like this.
Since I need to do some computation and decide which window to open, I do in the following way.
chrome.browserAction.onClicked.addListener(function(tab) {
if(...)
url="1.html";
else
url="2.html";
chrome.windows.create({url:url, type: "popup"});
});
But the window created has border and is not at the button's position.
How do I create a window that looks like the default popup?
If you dont figure out how to catch the event before the popup runs, you may do this (I do it for an extension of mine): Assuming both popups have the same width-height, always show popup1, and redirect (navigate to the other one) if it should show popup2. If you want to avoid flashing make sure both popups have fixed and equal body sizes.
Related
I have a couple of form definitions in my main HTML file.
I would like to display these forms in a modal window, when the user performs certain action, such as click on an icon.
I have followed an article on how to do it for links (hrefs). But now my requirement is to get the same working for clicking on an icon.
Thank you,
Harriet
The answer is to write a java function, that will explicitly set the location of the window to where you want the url to point - example:
function openPreferences() {
window.location = '#openPreferences';
}
I think the most simple solution would be to create a LinkBlock Element and set the Background to the Icon's Image, which will allow you to turn it into a Link, thus further allowing you to open your Modal Window with it.. Simply create your Modal as Display None, and upon clicking the LinkBlock (with your Icon as the Background), make it change the Modal property to Display Block, etc.
When a user clicks my browser action I'd like it's corresponding popup window to (almost) fill the screen. I need the:
height/width of the current window
WHEN
the user clicks my popup
I know I can get the height/width of the current window with chrome.windows.getCurrent(function(currentWindow) { console.log(currentWindow.height); });, however I don't know how to tell that my popup was opened (event), or how to dynamically set it's size (setting document.body.width or window.inner/outerWidth in the popup's inspector doesn't seem to do it). Thanks!
Edit: found http://code.google.com/chrome/extensions/browserAction.html#event-onClicked , however it says it will not fire it a browser action has a popup, is binding to onload in the popup page what I'm trying to achieve?
window.resizeTo resizes the browser window.
You can pass this information between your parent window and the child popup in any of many creative ways. The simplest I can think of that's pretty much assured to work would be to tack on the dimensions in a query string or hash for the child window URL and then to parse it with JS.
The usual disclaimer applies that there is almost always a better "way" to do things than resizing the browser window.
I'm trying to create a popup() where user clicks on button, then it triggers window where he does some edit.
While the user is editing in the child window, parent window should not be accessed, it should be blocked.
How exactly should i do this?
This is what i'm doing now.
function Popupwindow()
{
name = "Select Requestor";
url = "selectLocation.html";
options = "height=330, width=210, location=no, scrollbars=yes,menubars=yes,toolbars=yes,resizable=yes,left=0";
window.open(url,name,options);
}
So now i'm able to close parent window and even edit parent elements without closing child window.
What you want is called a modal dialog. There's no standard way to do this across multiple browsers, some don't even have anything like it. Your best bet is creating a modal dialog inside the page. Most JS frameworks/toolkits will provide dialogs.
don't use "real" popups, use javascript to "emulate" them in teh same window. take a look at jquerys dialog, where you can also set the modal-mode (example and example) - i think this is what you want.
there are a lot of standalone-js examples out thre if you're not using jquery and a lot of js-frameworks include things like this - just search for "modal dialog".
I'm making a chrome extension that uses pageAction.
I can set when it shows whether I want it to have a popup or handle the click myself.
What I want to do is handle the click myself, but with certain scenarios I don't want to process the normal code, and want to show the user a message. Preferably with a popup.
But it seams I can either make the pageAction have a popup or have an onClick. But not both.
I can show an alert, but that is ugly.
Currently, there is no "neat" or official way to handle both. You can just do either. But there are some work arounds that some Google extension product have done.
First of all, set it up to show the popup. And within your pageAction popup, you can have the initialization code to be something like this:
Page Action Popup:
function init() {
if (getClickBehaviour() == 'popup')
handlePopup();
else
openPage();
}
function getClickBehaviour() {
return localStorage['CLICK_BEHAVIOR'] || 'popup';
}
function openPage() {
chrome.tabs.create({url: 'http://google.ca'});
window.close();
});
}
init();
Then you can let your options, set the click behavior. If you want different behaviors on each click, you can do that too.
As you noticed, we are closing the popup right after for the "default" behavior that we don't want the popup to show. That is currently the only way to implement different behaviors.
I haven't tested this myself yet, but have you tried setting the popup to the empty string when you want to handle the click (chrome.pageAction.setPopup('')) and to your popup when you want to show a message. I'm not perfectly sure if the onClicked event handler gets called in that case (where the popup is dynamically set to the empty string), but it's worth looking into.
As far as I know, there is generally no way to programmatically open a popup window for a page or browser action. (Which is too bad, I would love this functionality; but you can imagine some of the annoyances if this were possible.)
I know how to show a pop-up window. But I will like to freeze or disable the parent window when there is a pop-up window active. Once the pop-up window is closed, the parent window should automatically be active again.
How exactly is it done?
You do not neet o remake the wheel.
Take a look at this page.
It's a JQuery plugin that does exactly what you ask, and much much more.
It is just my personal idea, but I would think, the solution could be when open the pop up windows, you just override the click function of the parent document to return false, and set it back to normal when they close the pop up window, some JavaScript code will need to be used here
I'm guessing you want a modal dialog box? Most of these disable the parent window by positioning an overlay... Here is a list of 22 different plugins ( you don't need to read German to use this site :P )