Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Using CSS to override target="_blank"

Using CSS to override target="_blank"
Thread Tools
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status: Offline
Reply With Quote
Feb 4, 2004, 05:29 PM
 
I'm new to the idea of using personal, custom style sheets to filter out unwanted content. It seems pretty interesting.

I was wondering, though, is it possible to use one of these personal style sheets to override links with the target="_blank" attribute so that they no longer open up in new windows?
     
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status: Offline
Reply With Quote
Feb 4, 2004, 05:42 PM
 
are you referring to Safari's ability to use it's own style sheet? if not, then i'm not quite sure what you mean.

i usually just hit the command button when i click a link which i can see will open in new window, so that it opens in a tab of my current window. that way, i don't have loads of windows open.
"Have sharp knives. Be creative. Cook to music" ~ maxelson
     
Turias  (op)
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status: Offline
Reply With Quote
Feb 4, 2004, 06:59 PM
 
Originally posted by philzilla:
are you referring to Safari's ability to use it's own style sheet? if not, then i'm not quite sure what you mean.

i usually just hit the command button when i click a link which i can see will open in new window, so that it opens in a tab of my current window. that way, i don't have loads of windows open.
Yeah, I'm refering to Safari (and other browsers) being able to use their own stylesheets.

And yeah, I usually do the same thing and open those links in another tab. I was just curious if you could override this behavior with a stylesheet.
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Feb 4, 2004, 08:04 PM
 
Not using any kind of standard CSS, no.

There may be some kind of Safari-exclusive extension which allows for this, but I don't know what it is.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Feb 5, 2004, 07:06 AM
 
Um, not sure about this, but I think you can include javascript in CSS (I doubt it supposed to be allowed, but...) which might allow you to do this. For example, if it allows you access to the document, you could just find if they are using a <base> element and change if - something like
Code:
var b = document.getElementsByTagName("base"); if (b.length > 0) b[0].setAttribute("target","_top");
I imagine you could also iterate through the link elements (<a>'s) adding/changing target attributes.

I should stress that I actually doubt this can be done for security issues, and I'm not sure if safari allows javascript to be embedded in CSS - I think it's a rough hack anyway. (it's something along the lines of
Code:
someSelector {javascript: function(){doWhatEver;};}
- but don't quote me on that. I glanced at some blog a few months ago and it was talking about that sort of thing).

Anyway - there you go. Stuff from the top of my head, and most likely not helpful
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Feb 5, 2004, 08:24 AM
 
Originally posted by Black Book:
Um, not sure about this, but I think you can include javascript in CSS (I doubt it supposed to be allowed, but...) which might allow you to do this. For example, if it allows you access to the document, you could just find if they are using a <base> element and change if - something like
Code:
var b = document.getElementsByTagName("base"); if (b.length > 0) b[0].setAttribute("target","_top");
That won't work for all links, though; a target attribute on and A tag overrides what's on the BASE tag.
I imagine you could also iterate through the link elements (<a>'s) adding/changing target attributes.
This is more what you'd have to do.

There is no standard way to include JavaScript in CSS. Gecko-based browsers and IE/Win have their own hacks which don;t directly let you include JavaScript in CSS, but will let you attach JavaScript to elements indirectly. Unfortunately, there is no standard for this, so it's different between IE/Win and Gecko, and Safari has nothing like it anyway.

From the way Hyatt talks about XBL (Gecko's way of doing something like this), that may someday be included in Safari. But right now, it is not.

Personally, I was always fond of the old Netscape proposal for CAS (Cascading Action Sheets; it's not JavaScript-in-CSS, but it's not all that far from it). No one ever implemented it -not even Netscape- but it would be incredibly useful.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Senior User
Join Date: Dec 2002
Status: Offline
Reply With Quote
Feb 5, 2004, 02:13 PM
 
middle-click all links
Travis Sanderson
     
Turias  (op)
Mac Elite
Join Date: Nov 2003
Location: Minnesota
Status: Offline
Reply With Quote
Feb 5, 2004, 02:22 PM
 
Originally posted by redJag:
middle-click all links
That doesn't really produce the desired effect...

Anyway, thanks for the ideas, guys. The idea of CAS sounds pretty neat, Millenium. Too bad it didn't take off.
     
Senior User
Join Date: Dec 2002
Status: Offline
Reply With Quote
Feb 5, 2004, 03:51 PM
 
Oops, sorry, didn't thoroughly read the post For anyone that didn't know, middle-clicking will open the link in a new tab (if you have tabs enabled). Does it do something else if you don't have tabs enabled?
Travis Sanderson
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:56 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2