Monday, June 3, 2024
153
rated 0 times [  154] [ 1]  / answers: 1 / hits: 36085  / 13 Years ago, tue, august 2, 2011, 12:00:00

I need to open a new pop up window on click of a button in a view. The new window should be redirect to a specific actionmethod in a specific controller. I also need to provide attributes for size of the new pop up window.
I have been trying the following code:



<input type=button name = ClickMe Value=ClickMe onclick= javascript:window.open('/Home/Create/','Customer Search',height='window.screen.height - 100', width='200',left='window.screen.width - 250' ,top='10',status='no',toobar='no',resizable='yes',scrollbars='yes')/>


On click of button, nothing happens. I get following Javascript error:




Line: 19

Char: 1

Error: Invalid argument.

Code: 0




When I check the ViewSource of the HTML rendered, I find the line to be the one which is rendering the button.
I am using Windows Vista with IE 7. I am working on MVC 3 with Razor Engine in VS 2010


More From » asp.net-mvc-3

 Answers
29

Respect html. Respect javascript. Respect the framework that you are writing on, that has made two big changes (validation and ajaxity) from its 2nd version to 3rd to apply the newer, modern principle - Unobtrusive Javascript. You could manage to correct that error in less time you spent on asking question in here if you followed that principle (with the help of vs javascript synthax highlighting).



    <input type=button id=ClickMe name = ClickMe Value=ClickMe />
...
<script type=text/javascript>
$(function () {
$('#ClickMe').click(function () {
window.open('/Home/Create/', 'CustomerSearch', 'height=' + (window.screen.height - 100) + ',width=200,left=' + (window.screen.width - 250) + ',top=10,status=no,toolbar=no,resizable=yes,scrollbars=yes');
});
});
</script>


And as I discovered, it's the issue with space in window name in IE - 'Customer Search'. If you remove that space - 'CustomerSearch', it'll start working in IE too


[#90866] Sunday, July 31, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
julieth

Total Points: 382
Total Questions: 99
Total Answers: 85

Location: Cape Verde
Member since Fri, Nov 27, 2020
4 Years ago
;