在Asp.net上使用JavaScript [英] Using JavaScript with Asp.net
问题描述
在单击LinkButton时,我正在使用JavaScript打开一个具有特定URL的新窗口.当我再次单击该链接按钮时,它将再次打开另一个窗口.但是我想再次单击该链接按钮,我想在同一窗口中打开该URL,该窗口在第一次单击该链接按钮时就会弹出.
我的代码在下面
Hi,
On clicking on LinkButton i am opening a new window with particular URL using JavaScript. When i am again clicking on that linkbutton it again opens another window. But i want that again clicking on that linkbutton i want to open that URL in the same window which gets popup on clicking the linkbutton at first time.
My code is given Below
void lnkViewOrderDocuments_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
if (null != Request.QueryString[CONST_OrderNo])
{
string dmuUrl = OrderHelper.SetDMULinkURLFromConfig(Request.QueryString[CONST_OrderNo].ToString(),
Request.QueryString[CONST_OrderType].ToString());
sb.Append(@"<script language='javascript' type='text/javascript'>");
sb.Append(dmuUrl.Trim());
sb.Append(@"</script>");
this.RegisterStartupScript("RegisterSalesTextScript", sb.ToString());
}
}
推荐答案
如果您使用的是window.open,则指定窗口名称,如下所示
例如:
if you are using window.open then specify windowname as below
for example :
window.open("htp://www.google.com","mycustomwindow")
尝试此Javascript函数:
Try this Javascript function:
function OpenURL()
{
var hdnFlag = document.getElementById(''<%= hdn.ClientID %>'');
if(hdnFlag.Value > 0)
{
window.location = "http://www.google.co.in";
}
else
{
hdnFlag.Value = 1;
window.open("http://www.google.co.in");
self.focus();
}
}
这里的"hdn"是页面中的隐藏字段,应该跟踪按钮是否已经被单击.
注意:请记住,在页面刷新时,此标志将被重置.
希望对您有所帮助!
Here "hdn" is a hidden field in the page which should keep track if the button is already clicked or not.
Note: Remember that on page refresh this flag will be reset.
Hope this helps!
如果是window.open,请使用window.showModalDialog
in case of window.open use window.showModalDialog
这篇关于在Asp.net上使用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!