I need to call an ASPX page from MVC view through below JavaScript code, also need to pass some parameter as query string,
function OpenTest() {
var width = (screen.availWidth - 700).toString();
var height = (screen.availHeight - 100).toString();
var param1 = "Test";
var baseUrl = '@Url.Content("~/Test/Test.aspx?")';
window.open(baseUrl + "param1=" + param1);
}
In ASPX page,
if(!string.IsNullOrWhiteSpace(Request.QueryString["param1"]))
{
string s1 = Request.QueryString["param1"];
}
I am able to call ASPX page and read parameter value by above code, but when I add other property of “window.open”, I am not able to read query string, question is where should I place below property in above code so that I can also read query string value in ASPX page,
"mywindow", "width=" + width + ",height=" + height + ",toolbar=no,location=no,directories=yes,status=no," +
"menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes" + ",screenX=0,screenY=0,left=0,top=0"
The syntax for
window.open()is:The
targetNamecan be “_self”, “_blank”, “_parent”, just like any target attribute for links, or have an identifier to name the window, so you can reuse the window when openning with the same name.When you calll
window.open()with any option to restrict the window, likewidth=100it assumes that all the other have to be disabled, so you don’t have to put the properties you want to disable.Fixing your options would be:
Another thing to note is that all options have to be separated by comas, without spaces. Some browsers ignore/missinterpret options with spaces.
Also, don’t forget to escape the variables to pass with the url.