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

robert stevens Robs_here at btinternet.com
Tue Mar 13 14:19:48 GMT 2007


Ok thanks, but now I'm confused. Do I just change the line in my javascript?
...This one: anchor.target = "_blank"; into this one:
window.open(this.href);
return false;

And the links in the XHTML stay the same?

Cheers,

R

> Dan Eastwell13/3/07 1:23 pmdaneastwell at gmail.com

> 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
>> 
> 




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