views:

75

answers:

4

Hi,

is it possible to use the window.location = "http://google.de" with _blank?

I dont want to use the <a href ... > at all, because it makes problems with the CSS (link-color).

You must always insert this code and that nervs :/

.bone a:link { color:#FFFFFF; text-decoration: none }
.bone a:visited { color:#FFFFFF; text-decoration: none }
.bone a:hover { color:#FFFFFF; text-decoration: none }
.bone a:active { color:#FFFFFF; text-decoration: none }
.bone a:hover { color:#FFFFFF; text-decoration: none }

Thanks in advance!

Peter

+1  A: 

Certainly, simply use window.open('http://www.example.com/', '_blank');

David Titarenco
+1  A: 

You probably need one CSS line:

.bone a { color:#FFFFFF; text-decoration: none }

Technically, this will also match non-link anchor tags. But you probably want those styled the same way. I think this is cleaner than a Javascript solution.

Matthew Flaschen
@Peter, that's correct. It won't work on some mobile browsers, or when JavaScript is turned off.
Matthew Flaschen
+1  A: 

I assume you're looking for something like:

var w = window.open("http://google.de", "_blank");

Bear in mind that it will shoot you in the foot as far as accessibility, search engine indexing, etc. go.

C-Mo
A: 

You must always insert this code and that nervs :/

You shouldn't have to insert all those. This should be enough:

.bone a {
  color: #FFFFFF;
  text-decoration: none;
}

If you find that's not enough, you probably have a specificity problem with your CSS; that is, you've specified different link colours elsewhere in CSS with same specificity but with different colours for hover, active etc. You get around that by making the rule you want to have effect here have a higher specificity than the global rule you want it to override.

Using Javascript to get around a styling problem is like buying a bicycle because you've lost your keys to your car.

Your Javascript won't work on browsers with Javascript disabled, search engine spiders won't be able to follow it, and who knows about mobile browsers or browsers for people with disabilities.

thomasrutter
// is like buying a bicycle because you've lost your keys to your car. ... hehe, funny example :)
Peter