Open link in new tab

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

TLN_CANADAAsked:
Who is Participating?
 
nickinthoozConnect With a Mentor Commented:
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
 
nickinthoozCommented:
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
 
TLN_CANADAAuthor Commented:
Thanks Nick, could you show me how to do this in my example as I need to pass the PHP also.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

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

Open in new window

0
 
nickinthoozCommented:
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
 
TLN_CANADAAuthor Commented:
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
 
TLN_CANADAAuthor Commented:
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
 
nickinthoozCommented:
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
 
nickinthoozCommented:
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
 
TLN_CANADAAuthor Commented:
Unfortunately this is giving no error but is not opening anything at all.
0
 
nickinthoozCommented:
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
 
TLN_CANADAAuthor Commented:
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
 
nickinthoozCommented:
here is a jsfiddle that's opening in a new tab for me

http://jsfiddle.net/eZhAH/3/
0
 
TLN_CANADAAuthor Commented:
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
 
TLN_CANADAAuthor Commented:
That's it! Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.