最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Need to open a new window with Javascript and pass query strings stored in a string variable in C# - Stack Overflow

programmeradmin3浏览0评论

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.

Share Improve this question edited May 20, 2014 at 19:54 Cody Hicks asked May 20, 2014 at 19:48 Cody HicksCody Hicks 4209 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

It'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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论