Solved

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

Posted on 2013-12-31
9
2,294 Views
Last Modified: 2014-01-07
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>
0
Comment
Question by:lippert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 4

Expert Comment

by:ItWorked
ID: 39749412
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 :)
0
 
LVL 1

Author Comment

by:lippert
ID: 39749487
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.
0
 
LVL 4

Expert Comment

by:ItWorked
ID: 39749699
@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.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 1

Author Comment

by:lippert
ID: 39750283
@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.
0
 
LVL 1

Accepted Solution

by:
lippert earned 0 total points
ID: 39750618
OK, I answered enough of the question myself that I'm willing to give myself the points.

This solution may not work in all browsers, but here it is.

I wanted to insure that the new window I am opening ALWAYS opens in a new window, not a new tab. Assuming the browser is set to use tabs, you can force the window to open as a new window if you:
1> open the new window, use the javascript "window.open" method.
2> In the javascript, if you put anything in the attributes parameter that contradicts the attributes fo the current window, the browser will force the window to open in a new window.

Examples:

The statement window.open("viewPDF", "My Document", ""); will follow the browser's settings to determine if the window is opened in a new window or a new tab.

The statement window.open("viewPDF", "My Document", "location=0, left=170, top=100, scrollbars=0"); will force the browser to open the page in a new window.
0
 
LVL 1

Author Comment

by:lippert
ID: 39750626
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.
0
 
LVL 4

Expert Comment

by:ItWorked
ID: 39750664
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!
0
 
LVL 1

Author Closing Comment

by:lippert
ID: 39758807
This may not work across all browsers as I didn't have time to test it beyond the two on my desktop.
0
 
LVL 1

Author Comment

by:lippert
ID: 39762195
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."
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question