Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  89] [ 3]  / answers: 1 / hits: 29188  / 12 Years ago, fri, july 20, 2012, 12:00:00

I have to open a window when a button is clicked, as a modal dialog using JavaScript.
I have used window.open, but it shows me two instances, the parent page and the pop-up page.
When the pop-up page is open, then do not allow the user to click on the parent page.



function openWindow() {
var w = 950;
var h = 350;
var t = 0;
var l = 0;
var scrollbars = 1;
var modal = 'yes';

var reportWindow = window.open(Search.aspx + '', '', width= + w + ,height= + h + ,left= + l + ,top= + t + ',scrollbars=' + scrollbars + 'modal' + modal);
reportWindow.focus();
}

More From » asp.net

 Answers
64

Your code line,



reportWindow = window.open(Search.aspx + '', '', width= + w + ,height= + h + ,left= + l + ,top= + t + ',scrollbars=' + scrollbars + 'modal' + modal);


is missing an '=' symbol after modal. It should be,



reportWindow = window.open(Search.aspx + '', '', width= + w + ,height= + h + ,left= + l + ,top= + t + ',scrollbars=' + scrollbars + 'modal=' + modal);


To open window as dialog box,



 <html>
<body>
<script language=JavaScript>
function openWindow() {
if (window.showModalDialog) {
window.showModalDialog(http://example.com,name,
dialogWidth:255px;dialogHeight:250px);
} else {
window.open('http://example.com','name',
'height=255,width=250,toolbar=no,directories=no,status=no, linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
}
}
</script>
<button onclick=openWindow();>Open window</button>
</body>
</html>


If the above code is not working, please use jQuery modal dialog. You can load any urls to dialog using an iframe.


[#84131] Thursday, July 19, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elliem

Total Points: 415
Total Questions: 117
Total Answers: 94

Location: American Samoa
Member since Fri, Aug 26, 2022
2 Years ago
;