Solved

Open link in new tab

Posted on 2013-02-02
15
487 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Find out what you should include to make the best professional email signature for your organization.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

809 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