Solved

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

Posted on 2013-12-31
9
2,214 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
  • 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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