Solved

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

Posted on 2013-12-31
9
2,090 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now