Jump to content


Photo

open link in new window using just css?


  • Please log in to reply
19 replies to this topic

#1 toolman

toolman

    Advanced Member

  • Members
  • PipPipPip
  • 157 posts

Posted 23 January 2013 - 04:40 AM

Hi,

Is it possible to open a link in a new window using just CSS?

I found this:

target-new: window;

but heard this isn't supported.

Any ideas?

Thanks

#2 BagoZonde

BagoZonde

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 23 January 2013 - 04:54 AM

Use of target="_blank" in anchor is the only way. As you probably know, W3C validation will tell you that there is no attribute "target" so it's an error, ehhh, so no solution? Here's one: who tell people that W3C is the prophecy? However target attribute in HTML5 is a valid one, if you're interested there's article about target attribute, W3C and HTML5: http://bryanhadaway....f-target-blank/

If you can't change PHP code or just don't want to, you could use Javascript/jQuery but I'm not using practices like that. Power of PHP is the key :).

That's all I know.

Edited by BagoZonde, 23 January 2013 - 04:58 AM.

A=1-A ...from Basic...
$a=1-$a ...thru PHP...
LDA $01 EOR #1 ...to 6502 ASM :}

Does it mean I'm going low-level?! ;]

#3 Frank P

Frank P

    Advanced Member

  • Members
  • PipPipPip
  • 168 posts

Posted 03 February 2013 - 05:00 PM

Hi,
Is it possible to open a link in a new window using just CSS?
I found this:

target-new: window;

but heard this isn't supported.


That is correct: http://www.w3schools...target-new.asp.

Edited by Frank P, 03 February 2013 - 05:01 PM.

Problem solved? Please click the button Mark Solved under the best post.

How to: Target IE in, Position in, Center in, Create a Fixed ('Sticky') Footer with, and Create a Drop-down/Fly-out Menu with CSS: Website Laten Maken Amsterdam.


#4 BagoZonde

BagoZonde

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 03 February 2013 - 05:05 PM

C'mon Frank, "the target-new property is not supported in any of the major browsers" - even this quote was taken from this W3C site.

Edited by BagoZonde, 03 February 2013 - 05:06 PM.

A=1-A ...from Basic...
$a=1-$a ...thru PHP...
LDA $01 EOR #1 ...to 6502 ASM :}

Does it mean I'm going low-level?! ;]

#5 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 03 February 2013 - 05:24 PM

Considering that W3C are the ones who define what HTML is, I don't think their authority on anything HTML (or CSS) related is in question.

Also, this is very easy to solve with a one-line Javascript function:
function newWin (targetURL) {
    window.open (targetURL, "_blank");
    return false;
}

Then just use onclick="return newWin (this.href)" on the links you want to open in a new window.
You can also use JS to register it to the click event, and prevent the default action, so that you don't have to change the HTML code at all.

Edited by Christian F., 03 February 2013 - 05:24 PM.

Keeping it simple.

#6 DavidAM

DavidAM

    Advanced Member

  • Gurus
  • 1,974 posts
  • LocationSpring, TX USA

Posted 03 February 2013 - 06:25 PM

Considering that W3C are the ones who define what HTML is, I don't think their authority on anything HTML (or CSS) related is in question.

(emphasis added)

+1 -- And remember w3schools has absolutely no relationship with W3C! It (w3schools) is an independant website that can't even be bothered to keep their content accurate and uptodate.
-- I haven't lost my mind, it's backed up on tape ... somewhere!

#7 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,709 posts
  • LocationBonita, FL

Posted 03 February 2013 - 10:04 PM

You can also use JS to register it to the click event, and prevent the default action, so that you don't have to change the HTML code at all.


Indeed, I tend to do something like this (jQuery):
$(function(){ 
  $('a.popup').click(function(e){
     e.preventDefault();
     window.open(this.href, 'popup');
     return false;
  });
});

Then in the html code I just do :
<a href="http://www.example.com/" class="popup">Example!</a>

If JS is enabled, it will open a new window, if it's not it works as a normal link.  You can also style it differently by just adding styles for the popup class if you want, such as an icon indicating an external link.

Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7

#8 Frank P

Frank P

    Advanced Member

  • Members
  • PipPipPip
  • 168 posts

Posted 04 February 2013 - 09:45 PM

C'mon Frank, "the target-new property is not supported in any of the major browsers" - even this quote was taken from this W3C site.

If you have something against w3schools, just say so.

Problem solved? Please click the button Mark Solved under the best post.

How to: Target IE in, Position in, Center in, Create a Fixed ('Sticky') Footer with, and Create a Drop-down/Fly-out Menu with CSS: Website Laten Maken Amsterdam.


#9 requinix

requinix

    Transforming Moderator

  • Moderators
  • 6,132 posts
  • LocationWA

Posted 04 February 2013 - 10:16 PM

If you have something against w3schools, just say so.

He's not the only one.

#10 BagoZonde

BagoZonde

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 05 February 2013 - 03:58 AM

If you have something against w3schools, just say so.


It's not about w3schools, is about your suggestion which lead to nowhere as there was said: "the target-new property is not supported in any of the major browsers". No Mozilla, no IE, no Opera, no Chrome.
A=1-A ...from Basic...
$a=1-$a ...thru PHP...
LDA $01 EOR #1 ...to 6502 ASM :}

Does it mean I'm going low-level?! ;]

#11 Frank P

Frank P

    Advanced Member

  • Members
  • PipPipPip
  • 168 posts

Posted 05 February 2013 - 05:06 AM

It's not about w3schools, is about your suggestion which lead to nowhere as there was said: "the target-new property is not supported in any of the major browsers". No Mozilla, no IE, no Opera, no Chrome.


And which is incorrect why, exactly??

Problem solved? Please click the button Mark Solved under the best post.

How to: Target IE in, Position in, Center in, Create a Fixed ('Sticky') Footer with, and Create a Drop-down/Fly-out Menu with CSS: Website Laten Maken Amsterdam.


#12 Frank P

Frank P

    Advanced Member

  • Members
  • PipPipPip
  • 168 posts

Posted 05 February 2013 - 05:10 AM

He's not the only one.


A bunch of nerds having nothing to do that scrutinized a web site which consists of many hundreds of pages, covering even many more topics, found a couple of matters that were not 100% correct. Big deal! Get a life! You'll like it!

Problem solved? Please click the button Mark Solved under the best post.

How to: Target IE in, Position in, Center in, Create a Fixed ('Sticky') Footer with, and Create a Drop-down/Fly-out Menu with CSS: Website Laten Maken Amsterdam.


#13 DavidAM

DavidAM

    Advanced Member

  • Gurus
  • 1,974 posts
  • LocationSpring, TX USA

Posted 05 February 2013 - 11:16 AM

They style themselves as a "school" (it's in the name), and they named the site in a way to imply (intentional or not) a relationship with the Consortium (W3C) that defines the standards. Then the don't keep their curriculum up-to-date. Any school that fails to keep their curriculum up-to-date is not worth "attending". Especially in the technology sector, teaching past "facts" that have changed, does not benefit the "students".

We, the members of this community, have had to "un-teach" the practices taught by that site, enough that we warn people away from it. If you want to ignore those warnings, on your head be it. At the very least, you now know that you need to take those teachings "with a grain of salt"; and when developing code using that site as a resource, problems you have may be the result of misinformation.
-- I haven't lost my mind, it's backed up on tape ... somewhere!

#14 Frank P

Frank P

    Advanced Member

  • Members
  • PipPipPip
  • 168 posts

Posted 06 February 2013 - 09:37 PM

Then the don't keep their curriculum up-to-date.


Total and utter BS as well. They have included CSS3 and HTML5 already in October 2011, and have converted their own site to HTML5 at that time as well. There is not one site, and I mean not one site in the whole world, that is that good when you combine content and didactics. Not one, and I dare you.

Problem solved? Please click the button Mark Solved under the best post.

How to: Target IE in, Position in, Center in, Create a Fixed ('Sticky') Footer with, and Create a Drop-down/Fly-out Menu with CSS: Website Laten Maken Amsterdam.


#15 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 07 February 2013 - 07:08 AM

Frank: Quality is not determined by quantity, often it's quite the opposite.
W3schools have a lot of incorrect information on their page, is copied wholesale from other manuals, and they can't be arsed to fix any errors reported to them. All of this is fact, easily verifiable by third party sources.
I don't know why you're taking it so personally, it is just (another) flawed web page.

In any case, this thread is not for discussing w3schools. So I'm quite certain that both the OP and the mods/admins would appreciate it if we all took this somewhere else.
Thank you.
Keeping it simple.

#16 Frank P

Frank P

    Advanced Member

  • Members
  • PipPipPip
  • 168 posts

Posted 07 February 2013 - 04:31 PM

Christian: my final post in this thread, but I didn't start this sub discussion on W3 Schools, I just made a reference to it which was perfectly appropriate in the original discussion.

You, on the other hand, did start with all kinds of insults to the authors of the site and stated all kinds of things that are greatly exaggerated at the very best, and unsubstantiated. Again in your last post. So it is utterly inappropriate that you are now asking to take it somewhere else.

#17 KevinM1

KevinM1

    Snarkimus Prime

  • Moderators
  • 5,230 posts
  • LocationNew Hampshire, USA

Posted 07 February 2013 - 07:17 PM

Frank, w3schools is widely considered to be an incomplete, and at times utterly wrong, reference. We don't support it's use here simply because we believe that incorrect information hinders learning. The 'nerds' you so easily dismiss are some of the industry's best and brightest. Simply put, they have the cachet to determine whether or not a resource is good or if it's harmful.

A far better resource to use is the Mozilla Developer Network (https://developer.mozilla.org/en-US/).

You taking criticism of w3schools personally is, quite frankly, bizzare. Neither Christian, nor David, nor requinix were insulting in their criticism. If you are in any way connected to w3schools (which is the only logical reason I can think of for your reaction), I think you'd be smart to take the criticism to heart rather than simply lashing out.

#18 Frank P

Frank P

    Advanced Member

  • Members
  • PipPipPip
  • 168 posts

Posted 07 February 2013 - 09:39 PM

In no way am I connected to W3 Schools. I have, however, looked at the criticism and found it to be without any significant weight, if valid at all. And all of you keep saying that it is a poor site, but none of you have offered any proof to that effect that will hold and has weight. The Mozilla site is, after the W3 site (not to be confused with the W3 Schools site), about the poorest I've ever seen in terms of didactics.

It's all talk, no walk. You have not come up with even just a reasonable alternative, let alone one that supersedes it.

Edited by Frank P, 07 February 2013 - 09:41 PM.

Problem solved? Please click the button Mark Solved under the best post.

How to: Target IE in, Position in, Center in, Create a Fixed ('Sticky') Footer with, and Create a Drop-down/Fly-out Menu with CSS: Website Laten Maken Amsterdam.


#19 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 07 February 2013 - 10:06 PM

In no way am I connected to W3 Schools. I have, however, looked at the criticism and found it to be without any significant weight, if valid at all. And all of you keep saying that it is a poor site, but none of you have offered any proof to that effect that will hold and has weight. The Mozilla site is, after the W3 site (not to be confused with the W3 Schools site), about the poorest I've ever seen in terms of didactics.

It's all talk, no walk. You have not come up with even just a reasonable alternative, let alone one that supersedes it.


This is the pot calling the kettle black if I ever saw it.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#20 KevinM1

KevinM1

    Snarkimus Prime

  • Moderators
  • 5,230 posts
  • LocationNew Hampshire, USA

Posted 08 February 2013 - 09:22 AM

In no way am I connected to W3 Schools. I have, however, looked at the criticism and found it to be without any significant weight, if valid at all. And all of you keep saying that it is a poor site, but none of you have offered any proof to that effect that will hold and has weight. The Mozilla site is, after the W3 site (not to be confused with the W3 Schools site), about the poorest I've ever seen in terms of didactics.

It's all talk, no walk. You have not come up with even just a reasonable alternative, let alone one that supersedes it.


You keep saying we haven't offered proof. When we offer proof in the form of w3fools.com, you then shift the goalposts by dismissing it as not being valid/not having any weight/being written by nitpicking nerds. When we explain that w3fools is written by some of the biggest names in web development, you still insist it isn't valid. When we offer a legit alternative, you dismiss it by saying it's almost as unclear as the W3C site, which is patently ridiculous to anyone that's taken time to look at both of them. At the end of the day, your 'counter-argument' boils down to simply, "Nuh uh!" which is hardly compelling.

You're entitled to your opinion. It's not shared by any respectable professional in this business, but you're entitled to it. That said, as a matter of course, we at PHP Freaks will never offer a link to w3schools as a solution to anything, and we will publicly criticize any post written by another that recommends it. Our purpose is to help people, and offering up incomplete or just plain wrong resources to people struggling to learn PHP and other web development skills is the opposite of helping.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com