I use the following code to display a popup:
var win = window.openDialog("chrome://broceliand/content/view/popup/nameMapPopup.xul",
"",
"all=no," +
"titlebar=no," +
"chrome=yes," +
"toolbar=no," +
"dialog=no," +
"resizable=no," +
"modal=yes," +
"dependent=yes," +
"top="+popupY+"px," +
"left="+popupX+"px",
args);
On windows the popup is pretty clean. There are no common elements remaining.
But on linux le titlebar still remains and the popup is resizable.
Try setting the hidechrome attribute on the window element to true. See https://developer.mozilla.org/en/xul/window
That might be because on Linux the window decorator is responsible for the titlebar. This can even be a seperate program to the window manager.
Does the popup need to be as a seperate window? Perhaps panel is really what you are looking for.
Related
I use the same code(Except the height parameter) to open linked-in and twitter share windows
window.open(
url,
title,
'_blank,directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,=no,width='
+ width + ', height=' + height + ', left=' + x + ',top=' + y
);
But they are replace each other and not opened in separate windows.
How do i open them in different windows.
The second argument to the window.open() function gives a name to the window being opened. If you use the same name as an existing window then that window is re-used. You set that argument from your title variable, so make sure your title is different for your Twitter and Linked-in windows and then they'll open in separate windows.
(If you want a new window every time then set the second argument as "_blank".)
Further reading: MDN's window.open() page
I use JQwidgets ,, I use to print data onclick print-button
as code :
$("#print").click(function () {
var gridContent = $("#jqxgrid").jqxGrid('exportdata', 'html');
var newWindow = window.open('', '', 'width=800, height=500'),
document = newWindow.document.open(),
pageContent =
'<!DOCTYPE html>\n' +
'<html>\n' +
'<head>\n' +
'<meta charset="utf-8" />\n' +
'<title>jQWidgets Grid</title>\n' +
'</head>\n' +
'<body>\n' + gridContent + '\n</body>\n</html>';
document.write(pageContent);
document.close();
newWindow.print();
});
When I close printing-widow(not continue printing), I can't use the grid-scroll (on chrome)..
google-chrome Version 34.0.1847.131 m
This worked fine on Firefox and IE..
How to fix the scroll after closing printing-window on chrome
Fiddle-Demo
It looks like you're not the only one with this issue.
I understand that your code is already setup and you want to run with what you have, but unless someone comes up with a hack or Google decided to fix what is clearly a bug, I think you need to re-think how you are approaching this issue.
If chromeless windows were an option, or if the print dialogue were a modal then you could pull this off with the current strategy, but neither of those options are possible in Chrome. Even if you were able to get around this scrolling issue somehow you're still left with a less than desirable UX problem in that if the user hits "cancel" in the print dialogue then they are left with a still open blank window.
Here is a JS fiddle to demonstrate that you need to change your approach: DEMO
You can see from this demonstration that even if we run a completely separate script from within the new window by passing it as plain text in the content object, it still causes the same issue. This means to me that this is a parent/child type of a relationship that is not easily circumvented with JS.
I recommend 2 alternative possible solutions:
Option1:
<input type="button" value="Print" onclick="window.print(); return false;" />
This triggers a full screen print dialogue that can't be closed from the "Windows Close Button." That way you can avoid the issue all together. Then you can use a combination of JS and Print Styles to target and isolate the information you want to print. I know it's more work but I think may be the better cross-platform solution.
This option is more brute force and simplistic in nature (and you have already commented that you know this but I'm leaving it up because it's still an option).
DEMO
Option2:
User clicks on a link/button that opens a new tab/window
In the same function the data from your table gets loaded into a JSON Object
The JSON object is loaded into a print template in the new tab/window
the template initiates the print function
By taking these actions, I think you will have disassociated the JS instance enough that the new tab will not affect the initiating script.
This is a browser bug - you'd have to find some sort of hack to fix it.
Doesn't sound like you want to put the print dialog code elsewhere thus not affecting your scroll bar. That is the obvious solution but it sounds like you can't do that.
Here's what I would do: Wait until someone has triggered the problematic condition, then put an event listener on the scroll event. when it happens... go ahead and reload the page.
Simple, easy, fun.
var needToReload = false;
$("#print").click(function () {
... as you have
needToReload = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
}
$('#contentjqxgrid').scroll(function () {
if (needToReload) {
window.location.reload();
}
});
$("#jqxscrollbar").jqxScrollBar({
width: 5,
height:180,
theme:'energyblue',
vertical:true
});
$("#jqxscrollbar1").jqxScrollBar({
width: 300,
height:5,
theme:'energyblue'
});
Look at jsfiddle: http://jsfiddle.net/8PtUX/6/
Is there a way I can send a key stroke to the browser from JavaScript? For example: I would like to trigger the key F11 through JavaScript so that my browser goes to theater mode.
No. You cannot send keystrokes to the browser with just pure javascript.
And the world is safe that way. Otherwise, the first thing i will do is if browser==firefox SendKeys(Alt + (T + I + S + W) and copy all the stored passwords
But if your intention is to have the browser in full screen mode (and you gave a legitimate reason to do so, like oprning a window with photos for slideshow for instance) you can
Open a pop up without the toolbars, address bar, status bar etc
or
Use flash/silverlight to open a full screen view (like in YouTube)
You can't. I presume "theater mode" means making the browser window fullscreen. Put simply, you cannot do this. It would be the source of enormous security flaws and usability problems if a website owner could do things like that to the browser window.
Would you like your browser to be continually jumping into fullscreen mode at the whim of the creator of a website?
As suggested by Nivas, I'm just posting the code snippet which i tried and was successful in achieving the fullscreen through javascript.
function fullscreen() {
params = 'width=' + screen.availWidth;
params += ', height=' + screen.availHeight;
params += ', fullscreen=yes';
params += ', status=no,titlebar=no,location=0,top=0, left=0';
window.open(window.location, "test", params);
}
I posted the code so that it would be a ready-made solution for one who is searching for fullscreen through javascript.
I have a problem with browsers window managament with javascript.
I have two page in my proof of concept application. First page contains login information (username, password, login button etc.) and second page is a managament screen. I need that when the user pressed to the login button on the login screen it open to main screen and main screen must be open new window without full screen. I mean close, minimize, maximize buttons and bottom bar of the windows os must be stayed on the screen.
During opening the new window on the login screen, it must be close itself automatically. I have found many example script but every script giving same results to me.
For example; following script solving my problem but same problems continue for me,
firefox does't close opener window it self,
ie 6.0 closing opener window - it's working
ie 7.0 - 8.0 before the close it self it asking "The webpage you are viewing is trying to close the window".
window.open("Content/StartPage.aspx", windowName, "menubar=0, location=0, resizable=1, status=1, width=" + screen.width + ",height=" + screen.height);
if (window.name != windowName) {
var me = window.self;
me.opener = window.self;
me.close();
}
How can i open new window and close the opener with above requirements without ask browsers question ?
Thank you.
You cannot do it according the security assurance of browser, there are some action which doesn't allow to be managed directly via javascript without user interference.
Try something like this in your new window, on the body onload:
function closeParent()
{
try
{
var op = window.opener;
op.opener = self;
op.close();
}
catch(er) {}
}
Still, this solution isn't perfect, I only got it to work in Internet Explorer, and even then, I got a warning popup for closing the parent window. This might be something that can't feasibly be solved.
i have Problem with opening popups in javascript i have this function to open my popups in IE6 and IE7:
function open_window(Location,w,h) //opens new window
{
var win = "width="+w+",height="+h+",menubar=no,location=no,resizable,scrollbars,top=500,left=500";
alert(win) ;
window.open(Location,'newWin',win).focus();
}
it's working . i mean my new window opens but an error occurs. The Error Message is :
'window.open(...)' is null is not an object.
do you want to countinue running script on this page ?
then i have button in onclick event it's will call a function to close current window an refresh the opener function is
function refreshParent(location)
{
window.opener.location.href = location ;
window.close();
}
it's also gives me error : window.opener.location is null or not an object but i'm sure i'm passing correct parameters
i call it like this :
for second part :
<input type="button" name="pay" value="test" onclick="refreshParent('index.php?module=payment&task=default')" >
for first part :
<a onclick="javascript:open_window('?module=cart&task=add&id=<?=$res[xproductid]?>&popup=on','500' , '500')" style="cursor:pointer" id="addtocard"> <img src="../images/new_theme/buy_book.gif" width="123" border="0"/> </a>
it's really confuse me . Please Help ;)
When popup windows opened using window.open are blocked by a popup blocker, a feature of pretty much any modern browser these days, the return value of window.open() is not a window object, but null.
In order to circumvent these issues you would need to test the value returned by window.open() before attempting to invoke any methods on it.
Below is a piece of code to demonstrate how to go around this problem:
function open_window(Location,w,h) //opens new window
{
var options = "width=" + w + ",height=" + h;
options += ",menubar=no,location=no,resizable,scrollbars,top=500,left=500";
var newwin = window.open(Location,'newWin',options);
if (newwin == null)
{
// The popup got blocked, notify the user
return false;
}
newwin.focus();
}
In general, popup windows should be used only as a last resort or in controlled environments (internal company website, etc). Popup blockers tend to behave in very inconsistent ways and there may be more than a single popup blocker installed in a given browser so instructing the user on how to allow popups for a given website is not necessarily a solution. Example: IE7 + Google toolbar = two popup blockers.
If I may suggest, perhaps you should consider using something like this:
http://jqueryui.com/demos/dialog/
The advantages are numerous:
Skinnable, so you can create a more consistent look to match your website.
No popup blockers.
Good API and documentation that is consistent across most, if not all, major browsers.
If you still require that the newly opened "window" contain an external URL, you could use an IFRAME inside the opened dialog window.
Hope this helps,
Lior.
Works perfectly fine for me. Tested in IE6/7/8.
Of course I couldn't test it with your URLs so I replaced these with simple filenames. I'd suggest you try it also with simple filenames and see if it also fails then.
Beside that...
You don't need to add "javascript:" at the beginning of onclick attribute value.
It would also be good if you added a href="..." attribute to the link with the same URL that you give to open_window. Then it would become a real link and you wouldn't have to add cursor:pointer to it. For example:
<a href="?module=cart&task=add&id=<?=$res[xproductid]?>&popup=on"
onclick="open_window(this.href, '500' , '500'); return false;"> ...
Here is a way to have your cake and eat it too
I have not tested it on all browsers but it should really work
function open_window(url,target,w,h) { //opens new window
var parms = "width="+w+",height="+h+",menubar=no,location=no,resizable,scrollbars,top=500,left=500";
var win = window.open(url,target,parms);
if (win) {
win.focus();
return false; // cancel the onClick
}
return true; // make the link perform as normal
}
Using the link
<a href="?module=cart&task=add&id=<?=$res[xproductid]?>&popup=on"
target="newWin"
onclick="return open_window(this.href,this.target,500,500)"
id="addtocard"><img src="../images/new_theme/buy_book.gif" width="123" border="0"/></a>
which even saves you the silly cursor thing since it is an actual link which works even when JS is turned off