Solved

Open link in new tab

Posted on 2013-02-02
15
484 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now