Disable the Maximixe, Close buttons in popup - javascript

In my web application(ASP.net), I used a Popup window using JavaScript. It is working perfectly but I need to Disable/Hide the Minimize, Maximize, Close buttons and the resizeable handlers too. Is it possible.... If it can be done, let me know how to achieve it.
My JavaScript is as follows:
function ApproveClick(url)
{
newwin =window.open(url,'PopupWindow','left=50, top=50, height=200, width=500,
toolbars=no,menubar=no,location=no,scrollbars=no,resizable=0,status=yes');
if(window.focus)
{
newwin.focus();
}
}

you could also use jQuery dialog box or MS Ajax control toolkit Modal Popup..

If you are looking for a cross browser solution (supporting at least IE, Firefox and Chrome), and trying to implement it only through parameters of window.open method, this is not possible. You can play around with dialog=yes,minimizable=no,maximizable=no options to see results but I suppose you won't be satisfied.
For example, in Chrome popups will always be resizeable when you are using window.open function.
So if you are looking for full control of your popups, go with something like javascript dialog (jQuery for example).

Related

HTML in a window

I want to make a window with HTML that works similar to ones opened by windows. I know the method with actual browsers, but it isn't good enough as I have link and navigation buttons.
This would make my job easier in making softwares with lots of animations
The best you can get is calling Window.open with third argument set as: 'menubar=no,location=no,resizable=no,scrollbars=no,status=no'.
This will open a new browser window with only the address bar shown.
There is no way to open a native window out of the browser's scope from JavaScript code other than this. It is a security limitation.
However, the other alternatives include are Window.alert or a Window.prompt.
If you want to open a popup box you can use alert("This is a dialog box!");, confirm("Is it ok or not?"); or prompt("Enter a value and confirm it or not");.
https://www.w3schools.com/js/js_popup.asp
If you want to open a native window, that is not possible as it has already been said.

How to disable maximize,mimimize and close button for a new window open

I am using window.open() method to open a page as a pop-up window for a link button click event.
But the poup-up window is having minimize,maximize,close(x) button.
I dont want those buttons. How can remove these buttons?
This is the method i am using,
window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,titlebar=no,scrollbars=1,resizable=0,width=450,height=310,left=500,top=350");
Tell me how can do this.
Regards,
Chirag Jain.
You can't.
If you want a popup style window without full window decorations you'd have to create a new overlay <div> on top of the existing content and fill that with content, perhaps using an <iframe>.
You can't do it from javascript alone. Think about it, if you could, then people could put it into code on web-pages and cause other people's computers to open windows they couldn't easily close.
Instead you'll have to look for an answer specific to whichever browser you're using to host this application, and change it on the computers of your users appropriately. Even then though I don't think you'll be in luck (with Firefox for example, I can see how to get rid of them on all browser windows, but not on just one).

How to show a modal dialog before beforeunload shows its own?

I do understand that it's not possible to replace the beforeunload dialog with a custom one, and that if we need to set a custom message to the user, we'll have to return a string in our beforeunload handler:
{Custom message here set by returning a string in our beforeunload handler}
Are you sure you want to leave this page?
[Leave this page] [Stay on this page]
So, how about showing a custom modal dialog (maybe jQuery) before the actual beforeunload dialog is shown by the browser?
My current code uses Fancybox:
window.onbeforeunload = function() {
$.fancybox({ 'type':'iframe', 'href':'/PopupOnExit.php' });
return "Special offer! Stay on this page for more details.";
};
However, this shows the browser's dialog first, and only after clicking either "Stay" or "Leave" buttons does the browser show my modal dialog.
Is there any way to make my modal dialog show before the the browser's dialog?
The DOM modifications take effect only when your script ends execution. In this case, the native dialog is fired first for obvious security reason.
Note that due to the many security problem introduced by this unspecified feature (see the MDN doc), it will maybe be removed (the soonest the best in my opinion), the old reason to have it (save the data) being obsolete in the age of ajax.
unload and onBeforeUnload are very not cross-browser events. Be careful.
It's not work in Opera and sometimes in Chrome.

Open new window after a click event not working in Safari, Chrome

I'm trying to open a new window like so:
$('#wrapper').click(function() {
window.setTimeout(function() {
//alert('hi');
window.open("http://example.com", "ExternalLinks", "resizable=yes, scrollbars=yes, status=yes");
}, 1000);
});
This works in Firefox, but not in Chrome or Safari (so far, I've just tested on a Mac). The alert() works in all browsers, so there seems to be something preventing the window.open from executing in Safari/Chrome. Furthermore, if I remove the setTimeout and just call the window.open then it does work in all 3 browsers. It's almost like if the window.open is nested too far away from the click event, then it doesn't work in Safari/Chrome.
So you know, I have an all-Flash website and I'm trying to get external links to open in a new window, so I'm reading the hash tag in the URL (ex. htp://example.com/#/facebook/) and if it matches certain items, then I'm calling window.open to open a specific URL. I don't have access to the Flash source, or I would handle this there.
Any ideas?
Safari/Chrome have built-in pop-up blockers that stop this from working. The only javascript that is allowed to open a new window in Safari/Chrome is javascript directly attached to click handlers (and other direct user input handlers). In past versions people figured out some ways to cheat (like generating some other element -- a form or div -- and simulating user input with javascript), but newer versions are smarter about detecting this. I'd recommend re-configuring things so that you don't use a delayed pop-up -- that is the kind of thing that can generally be jarring to a user after all.
I got around this by checking the return value of window.open() for undefined. If that is true call alert() with a message for the user to to disable their popup blocker.
var myWin = window.open([args]);
if (myWin == undefined)
alert('Please disable your popup blocker');
Another workaround
Just open a popup with ACCEPT and CANCEL options and attach the window.open action to the ACCEPT button and it will works. It worked for me...

Customizing the window popup skin?

Is there a way to customize the window layouts of popup that opens as a result of window.open event?
You could use jQuery UI to create a modal dialog box if you don't need an actual browser window.
If you mean you want to style the browser window this is not possible (not reliably across browsers as far as I know at least). You could open up your own-made popups inside the already opened website using javascript (then the popups would not be real popups but elements in the html DOM). Check out www.zkoss.org for an example using ajax for this if you are using java as a backend technology.
Demo:
Modal window demo

Categories