简体   繁体   English

在新标签页中打开URL,而不是在窗口后面使用C#代码打开URL

[英]Open URL in new tab instead of window using c# code behind

  • I have one PDF on my page. 我的页面上只有一个PDF。 But I want it to be opened only when a user is logged in. 但我希望仅在用户登录后才能打开它。
  • For that I use a popup with login on the PDF link. 为此,我在PDF链接上使用带有登录名的弹出窗口。
  • When he/she tries to login using this popup, the code behind it will come in to the picture. 当他/她尝试使用此弹出窗口登录时,其背后的代码将显示在图片中。
  • And from there I have to decide whether or not the user can open the URL. 从那里我必须决定用户是否可以打开URL。
  • If he/she is an authentic user, the page will get refreshed with the user login, and the PDF link will get opened in a new tab instead of a new window. 如果他/她是真实用户,则该页面将通过用户登录刷新,并且PDF链接将在新选项卡(而不是新窗口)中打开。

if you are using Hyperlink then use Target Attribute 如果您使用的是超链接,则使用目标属性

Behavior for Target Attribute is depend on Browsers 目标属性的行为取决于浏览器

 target="_blank"

older browser --> In New Window cause No tabbing Support. 较旧的浏览器->在“新窗口”中,导致没有制表符支持。

Newer browser---> new Tab. 较新的浏览器->新标签页。

and if You Want you use Button then markup your button definition like this, 如果您要使用Button,然后像这样标记您的按钮定义,

<asp:Button ........OnClientClick="NameofForm.target ='_blank';"/>

in code behind use redirection 在使用重定向后面的代码中

When user is authenticated, add a session variable to confirm authentication, use that session variable to check whether the user is authenticated or not and if authenticated, write a javascript code as: 用户通过身份验证后,添加一个会话变量以确认身份验证,使用该会话变量检查用户是否通过了身份验证,如果通过了身份验证,则将javascript代码编写为:

window.open("http://www.yahoo.com"); window.open( “http://www.yahoo.com”);

So, after your page is refreshed post authentication, the window will open. 因此,在验证后刷新页面后,将打开该窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM