1 (edited by nuuskamuikkunen 2007-09-25 23:46)

Topic: Open external links in new window

OK, I know, this has been discussed earlier...

Searched for "new window", "external links" etc and found things like

Open links in new tab/window

(including my own post on the subject, new-window links in a standards-compliant world wink )

Open links in a new window ("hack")

New Window Links Option for Users (extension)

etc etc

However, what I want to do now is: Open links to other sites in a new window.

1) I know it is the function "handle_url_tag" in /include/parser.php I have to modify, but how?

I want to compare the url to $pun_config['o_base_url'] , and then add the attribute rel="external" if it is an external link. (NB! All urls outside the forum subdomain are considered to be "external", i.e. http://example.com is an external link too, if o_base_url is http://forum.example.com.)

2) To change rel="external" into target="_blank" I use a javascript function.

In what pages do I have to include the .js file containing the script? The js function is needed in viewtopic.php, that is quite obvious, and in edit.php too (preview). Any other places?

Why I use rel="external" + javascript: Because a) I think it is prettier than adding onclick="window.open(this.href); return false;" and b) I want to do more things than just force the link to open in a new tab/window, e.g. add some info to the title attribute etc.

2

Re: Open external links in new window

The other ones I can think of are

1. Links to users websites which are in profile.php and viewtopic.php

2. Redirect URL's i.e. items which appear in the forum listing on index.php but which are actually redirects to external sites.

3. post.php has the preview as well as edit.php

4. You could replace the inline javascript used by the bbcode help system which means post.php, edit.php, viewtopic.php and profile.php.

Re: Open external links in new window

Hello! I've done this MOD. The only difference is I used target="_blank", but it's easy to modify (even if I prefer target than javacraps! :-P)

http://punbb.org/forums/viewtopic.php?id=17187