Javascript 如何在window.open函数ASP.NET中调用WebConfig appsetting值?

Javascript 如何在window.open函数ASP.NET中调用WebConfig appsetting值?,javascript,asp.net,web-config,window.open,Javascript,Asp.net,Web Config,Window.open,我必须使用webconfig appsettings更改此设置 在webconfig中,我有 <input id="Button1" type="button" value="button" onclick='window.open("https://google.com")' /> 我必须使用密钥获取url网络配置 我试过了 <add key="Google" value="https://google.com"/> 但它不起作用 您能否找到一种在windo

我必须使用webconfig appsettings更改此设置

在webconfig中,我有

<input id="Button1" type="button" value="button" onclick='window.open("https://google.com")' />

我必须使用密钥获取url网络配置

我试过了

<add key="Google" value="https://google.com"/>

但它不起作用


您能否找到一种在window.open函数中访问webconfig appsettings值的解决方案?

例如,尝试在代码隐藏中使用一个变量

<input id="Button1" type="button" value="button" onclick='window.open("<%= ConfigurationManager.AppSettings["Google"] %>")' />
然后在页面中

string openUrl = ConfigurationManager.AppSettings["Google"];

编辑-基于希望在aspx页面本身中这样做的评论(不确定为什么要这样做,但我相信你有你的理由)


例如,尝试在代码隐藏中使用变量

<input id="Button1" type="button" value="button" onclick='window.open("<%= ConfigurationManager.AppSettings["Google"] %>")' />
然后在页面中

string openUrl = ConfigurationManager.AppSettings["Google"];

编辑-基于希望在aspx页面本身中这样做的评论(不确定为什么要这样做,但我相信你有你的理由)


使用JS方法:

<% string openUrl = System.Configuration.ConfigurationManager.AppSettings["Google"]; %>
<input id="Button1" type="button" value="button" onclick='window.open("<%= openUrl %>")' />
以及:


或读取JS中的密钥

<input id="Button1" type="button" value="button" onclick='openUrl("<%= ConfigurationManager.AppSettings["Google"].ToString() %>")' />
函数openUrl(){ var url=''; var newWind=window.open(url“_blank”); newWind.focus(); } 使用JS方法:

<% string openUrl = System.Configuration.ConfigurationManager.AppSettings["Google"]; %>
<input id="Button1" type="button" value="button" onclick='window.open("<%= openUrl %>")' />
以及:


或读取JS中的密钥

<input id="Button1" type="button" value="button" onclick='openUrl("<%= ConfigurationManager.AppSettings["Google"].ToString() %>")' />
函数openUrl(){ var url=''; var newWind=window.open(url“_blank”); newWind.focus(); }
在aspx页面本身中有什么解决方案吗?我想如果您真的想走这条路,可以将变量声明包装在代码块中。请参阅我的编辑。aspx页面本身有什么解决方案吗?我想如果您真的想走这条路,可以将变量声明包装在代码块中。查看我的编辑。它工作正常。谢谢你的帮助。:)但是在双引号附近显示错误消息“unterminatedstringconstant”,它工作正常。谢谢你的帮助。:)但在双引号附近显示错误消息“unterminated string constant”