在新标签页中打开链接打开空白页面 [英] Open link in new tab is opening blank page
本文介绍了在新标签页中打开链接打开空白页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用
<ul> and <li>
标记并处理onserverclick事件,其中写入了重定向代码。此代码适用于正常点击。但是当我右键单击链接并选择在新选项卡中打开链接时,它会打开空白页面。那么我该如何处理这种情况呢。任何形式的帮助都会很好。在此先感谢。
以下是示例代码,
tags and handled onserverclick event, where redirection code is written. This code works fine for normal click. But when I right click on the link and select "Open link in new tab", it opens blank page. So how can I handle this scenario. Any kind of help will nice. Thanks in advance.
Following is the sample code,
<ul class="rounded-corners "> <li name="menuSample"><a onserverclick="lnk_clicked" runat="server" href="~/Sample.aspx" title="Sample">Sample</a></li>
</ul>
服务器端代码:
Server side code:
protected void lnk_clicked(object sender, EventArgs e)
{
strPage = (sender as System.Web.UI.HtmlControls.HtmlAnchor).Title.ToString();
Response.Redirect((sender as System.Web.UI.HtmlControls.HtmlAnchor).HRef);
}
推荐答案
点击你的ul元素〜/ Sample.aspx必须打开newtab
如果你想要上面的功能,不需要使用javascript函数aslo试试下面代码
By clicking on your ul element "~/Sample.aspx" has to open in newtab
If you want above functionality no need use the javascript function aslo try below code
<ul class="rounded-corners">
<li name="menuSample">
<a href="~/Sample.aspx" target="_blank">Sample<a>
</li>
<ul>
不知道为什么你又在这里处理服务器点击事件(你也确定有一个名为'onserverclick'的属性我不这么认为),因为只需设置'href'属性值应该适用于锚标签。
请删除添加为[onserverclick =lnk_clicked]的处理程序。
否则,如果它不起作用,您可以尝试添加以下属性价值如
Hi,
Not sure why are you again are you handling the server click event here(also are you sure there is an attribute named 'onserverclick' i m not thinking so), because simply setting the 'href' attribute value should work for the anchor tags.
Please remove handler being added as [onserverclick="lnk_clicked"].
Else if it is not working you can try with adding below attribute value like
target="_blank"
希望这将是帮助。
Hope this will be of help.
在此处查看更多信息 w3schools
这篇关于在新标签页中打开链接打开空白页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文