Re: opening link in new window

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jul 24, 2010 at 2:44 AM, Robert Cummings <robert@xxxxxxxxxxxxx>wrote:

> On 10-07-24 02:06 AM, Paul M Foster wrote:
>
>> On Sat, Jul 24, 2010 at 01:08:49AM -0400, Robert Cummings wrote:
>>
>>  On 10-07-24 12:58 AM, Paul M Foster wrote:
>>>
>>>> On Fri, Jul 23, 2010 at 01:28:23AM -0400, David Mehler wrote:
>>>>
>>>>  Hello,
>>>>> I've got a page with an external link. I'd like to open it in a new
>>>>> window, but i'm using the xhtml 1.0 strict dtd so this isn't possible.
>>>>> I was wondering if php could pull this off? Failing that, and not
>>>>> really wanting to go there, would javascript work for this?
>>>>> Thanks.
>>>>> Dave.
>>>>>
>>>>
>>>> I take it
>>>>
>>>> <A HREF="newwindow.html" TARGET="_blank">a new window</A>
>>>>
>>>> is not part of the xhtml 1.0 strict dtd? Because I recently solved this
>>>> problem using the above syntax.
>>>>
>>>
>>> The GP is correct, target="_blank" is not valid XHTML 1.0 strict.
>>>
>>> Here's some JavaScript to put in your page and run once the page
>>> completes loading. It looks for anchors having rel="nofollow" and
>>> rel="external" attributes in anchors and adds a target="_blank"
>>> attribute.
>>>
>>>     function bahHumbugExternalLinks()
>>>     {
>>>         if( !document.getElementsByTagName )
>>>         {
>>>             return;
>>>         }
>>>
>>>         var anchor  = null;
>>>         var anchors = document.getElementsByTagName( 'a' );
>>>
>>>         for( var i = 0; i<  anchors.length; i++ )
>>>         {
>>>             anchor = anchors[i];
>>>
>>>             if( anchor.getAttribute( 'href' ) )
>>>             {
>>>                 if( anchor.getAttribute( 'rel' ) == 'nofollow'
>>>                     ||
>>>                     anchor.getAttribute( 'rel' ) == 'external' )
>>>                 {
>>>                     anchor.target = "_blank";
>>>                 }
>>>             }
>>>         }
>>>     }
>>>
>>>
>> You know, if you're going to sneak target="_blank" in the back way in
>> order to avoid antagonizing the xhtml 1.0 deities, it seems like it'd be
>> easier to just say:
>>
>> <?php echo '<A HREF="newwindow.html" TARGET="_blank">a new window</A>';
>> ?>
>>
>> Or, wait. With javascript, you're hacking the DOM. If you put my PHP
>> above in the file, the offending code will arrive at the client browser.
>> Will the xhtml 1.0 deities cast you into the pit of hell if this
>> happens?
>>
>
> Canadian Federal Government requires that all public government websites
> validate to XHTML 1.0 strict. The validation is performed on what arrives at
> the browser, not what arrives at the PHP interpreter :)
>
>
> Cheers,
> Rob.
> --
> E-Mail Disclaimer: Information contained in this message and any
> attached documents is considered confidential and legally protected.
> This message is intended solely for the addressee(s). Disclosure,
> copying, and distribution are prohibited unless authorized.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Code that resembled the below is how I used to open new windows before I
started using jQuery  Note, this completely avoids use of the target
attribute.

function wireNewWindows(){
   if(document.getElementsByTagName){
      var anchors = document.getElementsByTagName("a");
      for(var i = 0; i < anchors.length; i++){
         var node = anchors[i];
         if(node.getAttribute('rel') == 'external' ||
node.getAttribute('rel') == 'nofollow'){
            node.onclick = function(){
               var url = this.href;
               window.open(
                  url,

 'newWin','width=700,height=500,Menubar=yes,Toolbar=no,Location=no'
               );
               return false;
            }
         }
      }
   }
}

Adam

-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux