Avatar of lippert
lippert
Flag for United States of America asked on

How do I make asp:hyperlink control force to open a new page?

I have a asp:hyperlink control for which I am setting the NavigateURL value dynamically. I want to 'force' the link to ALWAYS open in a new window across ALL browsers. With Target="_blank" currently it sometimes opens in a tab and sometimes in a new window, but for this specific instance I want it to always open a new window.

<asp:hyperlink ID="PDF_Link" Target="_blank" NavigateUrl="~\random.pdf" runat="server"> <img height="24px" width="24px" src="Images/PDF_1.jpg" /> </asp:HyperLink>
ASP.NET.NET Programming

Avatar of undefined
Last Comment
lippert

8/22/2022 - Mon
Hiran Desai

Hello,
You can not control the behavior of the browser.Opening a new tab/window is functionality defined by the browser.


Say for example for the following code
<a href="#" target="_blank" >Click me!</a>
or for 
<a href="#" click="return function(){ window.open('http://google.com');return false; }">click me!</a>

Open in new window


Chrome Version 31.0.1650.63 m open up new window
firefox opens new tab
IE-11 opens up tab
IE-9 opens up new window


So that's browser developers who are making this thing variant.
hope this is helpful :)
lippert

ASKER
There's got to be a way to work around this. In all of the browsers you mentioned above, I have experienced instances where some pages are opened as a new window and others are opened in a new tab. I There is some content related attribute that causes the browsers to act differently in some situations. Just as one example, in Chrome, CTRL+t opens a new tab and CTRL+n opens a new window. I have trouble believing thay there's no way to do that from code... Think about it...

P.S. I don't give out points for telling me it can't be done.
Hiran Desai

@lippert,
Expert Exchange is just not about earning points. It's more about experts are sharing their knowledge and are also here to learn something from the questioners.

Anyway, If there would be a way, I would like to know how that can be done so that It'll even help me to improve my knowledge.

BTW I'm here not be expert but I'll share my knowledge where ever I would like to.

Thank you.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
lippert

ASKER
@itWorked,

Thank you for your comment, but if there's one thing I've learned in 35 years of of software development, it's that "It can't be done!" is seldom true. It ususally means "I've never done it before, I don't know how to do it and I heard somewhere that it can't be done." I've never told my employer that it can't be done until I've invested enough time to know from personal experience that it can't.

Some of you might take this comment as a flame, but a few of you will take it as a challenge.
ASKER CERTIFIED SOLUTION
lippert

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lippert

ASKER
Just a general comment to everyone, please don't be so quick to say something can't be done unless you've invested your own time in trying to solve the same problem. Obviously some things that can't be done actually can be done.
Hiran Desai

This was what my first comment. The solution can't handle behavior of the browser.
Anyway the solution is not working in IE...which does not support more then one argument in window.open .


But good thing is I have learned new thing is setting extra parameter for window properties can also override setting of User!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
lippert

ASKER
This may not work across all browsers as I didn't have time to test it beyond the two on my desktop.
lippert

ASKER
The solution does work in IE for the 'average user' who has not changed the default IE "Tabs" setting of "Let Internet Explorer decide how pop-ups should open."