homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

Opening new window not working on Mac, Safari
Replaced target="_blank" with rel="external"

 10:14 am on Sep 21, 2006 (gmt 0)

I have a few external links (inside an IFrame) which I have set target="_blank" on the anchor tags. These links do not open in new windows in Safari.

The next step was to be more Standards-Compliant and so I replace target="_blank" with rel="external" and then called some JavaScript for the external links. JavaScript code below:

function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
window.onload = externalLinks;

This works in IE and Firefox. Any ideas how to get this working on Safari, or what is the correct way of opening links in new windows?



 10:27 am on Sep 21, 2006 (gmt 0)

Just to expand on this... It also does not work in Firefox on the Mac. The JavaScript file is called from within the head section of the main page and I have tried copying the external JavaScript code into the page (as I'm aware that JS sometimes only works when it is on the page, instead of in a seperate file) and that doesn't work either. Comments appreciated.


 11:49 am on Sep 21, 2006 (gmt 0)

Try using the standard array Links instead of calling getElementsByTagName(). However, I doubt that is the cause of the problem.

You need to break up the code and use alert() to find out where it's going wrong. However, if Safari supports it, try either turning on error reporting or opening a javscript console to (view error messages). I've never used Safari but it should support one of these.

It's also possible that the code is fine but you need to change a setting on Safari.

It might even be doctype-related, maybe.



 12:08 pm on Sep 21, 2006 (gmt 0)

You could try changing:
anchor.target = "_blank";


Just a thought?!


 12:10 pm on Sep 21, 2006 (gmt 0)

target="_blank" works fine for me on a Mac in both Safari and Firefox, and it always has. Must be something local to your system.


 10:57 am on Sep 22, 2006 (gmt 0)

Thanks for all your responses. Neither of the suggestions worked, however I played around with the JS in the header sections and today it's fixed. Sometimes it's good to sleep on "stuff"...

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved