Jump to content

open link in new window using just css?


toolman

Recommended Posts

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
Link to comment
Share on other sites

  • 2 weeks later...

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.
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.