Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Open link in new tab

Posted on 2013-02-02
15
Medium Priority
?
499 Views
Last Modified: 2013-02-02
Hi everyone,

At the moment this page opens in the same tab and I wonder how I could open it in a separate tab?

 <input type = "button" value = "Export Journal" target="_blank" onClick = "parent.location.href = 'http://www.clear.com/export.php?username=<?php echo htmlentities($username); ?>'

Open in new window

0
Comment
Question by:TLN_CANADA
[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
  • 8
  • 7
15 Comments
 
LVL 6

Expert Comment

by:nickinthooz
ID: 38847279
try to do it with css3,
#div a { target-new: tab ! important };

Open in new window


http://www.w3.org/TR/2004/WD-css3-hyperlinks-20040224/
0
 

Author Comment

by:TLN_CANADA
ID: 38847287
Thanks Nick, could you show me how to do this in my example as I need to pass the PHP also.
0
 
LVL 6

Expert Comment

by:nickinthooz
ID: 38847290
you can also use target="_blank" in your a tag
<a href="www.google.com" target="_blank">link</a>

Open in new window

0
Technology Partners: 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!

 
LVL 6

Expert Comment

by:nickinthooz
ID: 38847298
in your css file put

input[type=button] {
 target-new: tab ! important;
 }

then


<input type = "button" value = "Export Journal"  onClick = "parent.location.href = 'http://www.clear.com/export.php?username=<?php echo htmlentities($username); ?>'
0
 

Author Comment

by:TLN_CANADA
ID: 38847301
Hi Nick,

You can see from my code above that I already had the target blank included. I tried removing the "parent.location" part but it does not open the link at all then.
0
 

Author Comment

by:TLN_CANADA
ID: 38847309
Thanks Nick, I have lots of other buttons on the page though and only want this one to behave this way, how can I alter the CSS to cater for this?
0
 
LVL 6

Expert Comment

by:nickinthooz
ID: 38847311
try this
<input type = "button" value = "Export Journal"  onClick = "this.form.target='_blank';parent.location.href = 'http://www.clear.com/export.php?username=<?php echo htmlentities($username); ?>'

Open in new window

0
 
LVL 6

Expert Comment

by:nickinthooz
ID: 38847316
To answer your question:
you'll have to assign a name to the div it's in or a class to the button:

#yourdiv input[type=button] {
 target-new: tab ! important;
 }

Open in new window


then:

<div id="yourdiv"><input type = "button" value = "Export Journal" target="_blank" onClick = "parent.location.href = 'http://www.clear.com/export.php?username=<?php echo htmlentities($username); ?>'</div>

Open in new window

0
 

Author Comment

by:TLN_CANADA
ID: 38847322
Unfortunately this is giving no error but is not opening anything at all.
0
 
LVL 6

Expert Comment

by:nickinthooz
ID: 38847338
have you tried window.open?

<input type = "button" value = "Export Journal"  ONCLICK="window.open('http://www.clear.com/export.php?username=<?php echo htmlentities($username))'; ?>'

Open in new window

0
 

Author Comment

by:TLN_CANADA
ID: 38847351
Here is what I'm trying for ONCLICK

ONCLICK="window.open('http://www.clear.com/export.php?username=<?php echo htmlentities($username))'; ?>'"

Open in new window


but gives the error

Parse error: syntax error, unexpected ')', expecting ',' or ';'
0
 
LVL 6

Expert Comment

by:nickinthooz
ID: 38847353
here is a jsfiddle that's opening in a new tab for me

http://jsfiddle.net/eZhAH/3/
0
 
LVL 6

Accepted Solution

by:
nickinthooz earned 2000 total points
ID: 38847356
ONCLICK="window.open('http://www.clear.com/export.php?username=<?php echo htmlentities($username);?>')"

Open in new window


try that, comma was out of order.
0
 

Author Comment

by:TLN_CANADA
ID: 38847359
Hmm, I have the page opening in a iframe so this might be the problem.

When I insert your code directly it gives the error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in
0
 

Author Closing Comment

by:TLN_CANADA
ID: 38847366
That's it! Thank you!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

715 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