Solved

Open link in new tab

Posted on 2013-02-02
15
482 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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)

747 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

13 Experts available now in Live!

Get 1:1 Help Now