[BNM] [Bulk] Re: XHTML strict New Window

Dan Eastwell daneastwell at gmail.com
Tue Mar 13 13:23:56 GMT 2007


Haha! Sorry, I thought I was replying to the jquery forum!! Either
way, the same principles apply.

Well, the idea is to use jquery to iterate over the page and find all
links with the attribute rel and the value 'external', which is what
the function below does, as well, and then pops them in a node
collection to play with.

Your function also adds a target="_blank" to open a window, relying on
what the browser does/is allowed to do (with pop up blockers, etc).

instead of the line

anchor.target = "_blank";

use

window.open(this.href);
return false;

you might have more joy with pop up blockers. It will failsafe to a
straightforward link without javascript.

HTH, any more questions, just ask,

Dan

On 3/13/07, robert stevens <Robs_here at btinternet.com> wrote:
> Thanks Dan!
>
> Umm, I'm no JS maestro here. You don't mean to change anything in my HTML
> links do you? They can stay like this:
> <a href="document.html" rel="external">external link</a>
>
> This is how the jS is now
> ------------------------------
> 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;
> -------------------------------
>
> Do you mean to write an additional function?
>
> Thanks,
>
> Rob
>
> -------------------------------
> > Dan Eastwell13/3/07 11:48 am daneastwell at gmail.com
>
> > Try as well as rel="external" as your HTML trigger, using the following:
> >
> > externalWindow("a[@rel='external']");
> >
> > in your document.ready
> >
> > and
> >
> > function externalWindow(theElement){
> > $(theElement).click(function() {
> > window.open(this.href);
> > return false;
> >   });
> > }
> >
> > This should work.
> >
> > On 3/13/07, robert stevens <Robs_here at btinternet.com> wrote:
> >> Dear all,
> >>
> >> I'm having to use pop up windows for external links (and a few internal
> >> too). As you XHTML strict peeps will know, using target="_blank" in the HTML
> >> for this will fail XHTML strict in the WC3 Validator.
> >>
> >> Have researched some simple JavaScript options for this. One that kept
> >> cropping up, and I have tried to use, is this:
> >> http://www.sitepoint.com/article/standards-compliant-world
> >>
> >> However, in Safari and Firefox (OS X) it doesn't open a new window.
> >> It's possible I've made an error. Does anyone know a robust standards
> >> compliant new window opener that will work in Safari and Firefox (Mac)?
> >>
> >> Many thanks,
> >>
> >> Rob
> >>
> >> --
> >>
> >> BNM Subscribe/Unsubscribe:
> >> http://lists.wessexnetworks.com/cgi-bin/mailman/options/bnmlist/
> >> BNM info/archives:
> >> http://www.brightonnewmedia.org/
> >>
> >> BNM archive search:
> >> http://www.roddis.org/bnm/search.php
> >>
> >> BNM powered by Wessex Networks:
> >> http://www.wessexnetworks.com
> >>
> >
>
> --
>
> BNM Subscribe/Unsubscribe: http://lists.wessexnetworks.com/cgi-bin/mailman/options/bnmlist/
> BNM info/archives:
> http://www.brightonnewmedia.org/
>
> BNM archive search:
> http://www.roddis.org/bnm/search.php
>
> BNM powered by Wessex Networks:
> http://www.wessexnetworks.com
>


-- 
Daniel Eastwell

Portfolio and articles:
http://www.thoughtballoon.co.uk

Blog:
http://www.thoughtballoon.co.uk/blog



More information about the BNMlist mailing list. Powered by Wessex Networks