[英]How WebConfig appsetting value can be called inside a window.open function ASP.NET?
<input id="Button1" type="button" value="button" onclick='window.open("https://google.com")' />
我必须使用webconfig appsettings更改此设置。
在webconfig中,我有
<add key="Google" value="https://google.com"/>
我必须使用密钥获取url webconfig。
我努力了
<input id="Button1" type="button" value="button" onclick='window.open("<%= ConfigurationManager.AppSettings["Google"] %>")' />
但它没有用。
你能找到一个解决方案来访问window.open函数中的webconfig appsettings值吗?
例如,尝试在后面的代码中使用变量
string openUrl = ConfigurationManager.AppSettings["Google"];
然后在页面中
<input id="Button1" type="button" value="button" onclick='window.open("<%= openUrl %>")' />
编辑 - 基于想要在aspx页面本身做的评论(不知道你为什么要这样做,但我确定你有你的理由)。
<% string openUrl = System.Configuration.ConfigurationManager.AppSettings["Google"]; %>
<input id="Button1" type="button" value="button" onclick='window.open("<%= openUrl %>")' />
使用JS方法:
function openUrl(url) {
var newWind = window.open(url, '_blank');
newWind.focus();
}
和:
<input id="Button1" type="button" value="button" onclick='openUrl("<%= ConfigurationManager.AppSettings["Google"].ToString() %>")' />
或者在JS中读取密钥
function openUrl() {
var url = '<%=ConfigurationManager.AppSettings["Google"].ToString() %>';
var newWind = window.open(url, '_blank');
newWind.focus();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.