Welcome Guest, Not a member yet? Register   Sign In
Accessibility enhancement to anchor_popup function in the url helper
#1

[eluser]Gabriel Svennerberg[/eluser]
I've made a slight enhancement of the way the anchor_popup function renders the output html. Since using the pseudo-protocol javascript[colon] isn't part of any web standard and also leaves users with javascript turned off with a useless link. I've changed the way the url renders.

So instead of

Code:
return "<a href='javascript[colon]void(0);' onclick=\"window.open('".$site_url."', '_blank');\">".$title."</a>";

I use this

Code:
return "<a href=\"".$site_url."\" onclick=\"window.open(this.href, '_blank'); return false;\">".$title."</a>";

This way users with no javascript can still use the link, only it doesn't open in a new window. This is also better for SEO.

The whole shebang
Code:
function anchor_popup($uri = '', $title = '', $attributes = FALSE)
{    
    $title = (string) $title;
    
    $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri;
    
    if ($title == '')
    {
        $title = $site_url;
    }
    
    if ($attributes === FALSE)
    {
        return "<a href=\"".$site_url."\" onclick=\"window.open(this.href, '_blank'); return false;\">".$title."</a>";
    }
    
    if ( ! is_array($attributes))
    {
        $attributes = array();
    }
        
    foreach (array('width' => '800', 'height' => '600', 'scrollbars' => 'yes', 'status' => 'yes', 'resizable' => 'yes', 'screenx' => '0', 'screeny' => '0', ) as $key => $val)
    {
        $atts[$key] = ( ! isset($attributes[$key])) ? $val : $attributes[$key];
    }

    return "<a href=\"".$site_url."\" onclick=\"window.open(this.href, '_blank', '"._parse_attributes($atts, TRUE)."'); return false;\">".$title."</a>";
}
#2

[eluser]xwero[/eluser]
i don't see anything that generates a link, new window or otherwise, in your code??
#3

[eluser]Gabriel Svennerberg[/eluser]
You're right I don't see anything either. This is strange. In the preview of the post the code was definitely there but once submitted it's gone. It's got to be some kind of filter filtering out "suspicious" code.

Hm.. Where it says return "" it should be:

Code:
return "[angel-bracket]a href=\"".$site_url."\" onclick=\"window.open(this.href, '_blank'); return false;\"[angel-bracket]".$title."[angel-bracket]/a[angel-bracket]";

Replace [angel-bracket] with the real thing.

I hope this works. Otherwise email me and i'll send you the code.
#4

[eluser]Derek Allard[/eluser]
Ah yes, its probably our filtering. One quick way around that is to your your code out, into a text document, and zip it for attachment to the forums. Sorry Gabriel, and welcome to CI!
#5

[eluser]Gabriel Svennerberg[/eluser]
Thanks for the advice, but when I tries to submit the post with the attached zip-file I get an error message saying:

Quote:Error Message: The filetype you are attempting to upload is not allowed
Allowed Filetypes: image

Is there anywhere else I can upload it?
#6

[eluser]Derek Allard[/eluser]
Oh goodness... I'm sorry. Try the wiki
http://www.codeigniter.com/wiki or if that's too much, email me directly at derek.allard at ellislab dot com and I'll get it into this thread for you.
#7

[eluser]Derek Allard[/eluser]
OK, think I got it. I just replaced every < with &amp;lt; to force it to display correctly. Take a look and let me know if that's the function you wanted.
#8

[eluser]xwero[/eluser]
Maybe there should be a user guide to post javascript code Smile For the script tag i use &amp;lt;script&amp;gt;

As far as the changed function goes i think the new window with attributes still doesn't generate a link.
#9

[eluser]Gabriel Svennerberg[/eluser]
Now I've edited the post so it shows the code correctly. Thanks for the tip about using the html entity for the angel brackets. Should have thought of that myself...
#10

[eluser]Nikhil Vijayan[/eluser]
Thats a great idea Gabriel .. Thanks ..




Theme © iAndrew 2016 - Forum software by © MyBB