I may be going about this all wrong but I am trying to set up a normal HTML button on the client side, using javascript and Window.Open
to determine the page url, size, position, etc.
What I would like to do is pass local variables from code-behind and some how attach the query string segment to the url within the Window.Open
script dynamically. What I was thinking of doing is constructing the query string in the code behind and assign it to a string variable. I would the like to simply attached the variable from code-behind to the query string segment of the url, in the Window.Open
script.
Something like this, although I this isn't working...
<input type="button" value="Printer Friendly Copy" onclick="window.open('Print.aspx?<%= MyString %>', '_blank', 'toolbar=no, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400')" />
Could anyone tell me the proper way of doing this? I could navigate to a new page all together using Response.Redirect
in code-behind but I would prefer to open a new window and so far, javascript seems to be the best way of doing this from my research.
I may be going about this all wrong but I am trying to set up a normal HTML button on the client side, using javascript and Window.Open
to determine the page url, size, position, etc.
What I would like to do is pass local variables from code-behind and some how attach the query string segment to the url within the Window.Open
script dynamically. What I was thinking of doing is constructing the query string in the code behind and assign it to a string variable. I would the like to simply attached the variable from code-behind to the query string segment of the url, in the Window.Open
script.
Something like this, although I this isn't working...
<input type="button" value="Printer Friendly Copy" onclick="window.open('Print.aspx?<%= MyString %>', '_blank', 'toolbar=no, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400')" />
Could anyone tell me the proper way of doing this? I could navigate to a new page all together using Response.Redirect
in code-behind but I would prefer to open a new window and so far, javascript seems to be the best way of doing this from my research.
2 Answers
Reset to default 3It's not entirely clear to me what you're asking, but if you simply want to open a new window with a url that contains parameters, that is certainly possible.
Note that you must open the new window only in response to a UI event, like a button click, or the browser will assume it's malicious and block it.
My question is what you are doing with
<%= MyString %>
is that a variable you want to fill in? If so, you should simply construct the url in Javascript.
var url = "Print.aspx?" + variables;
window.open(url, ...)
Here is a simple fiddle showing this: http://jsfiddle/LvB7Z/1/
Set your value in the code-behind into a hidden field with a unique name or class. On the client side, use javascript/jquery to find that hidden field and then use window.open passing it the query string key/value.
For example, var vals = $('#myHiddenField').val();
in jquery notation. or use getElementById in js.
HTH