External Link / Leaving Site Warning

Hi,

Im stumped at the first hurdle, so not going too well so far!

How can I set a TbMenu item link to contain rel="external" so that I can use JS to open in a blank window?


Secondly, has anyone got a cute script that will also say “hey, you’re leaving this site… [ok][cancel]”

Personaly, this is annoying to most users, but it’s a legal requirement on this project.

p

Say theres an external link in there, to a new site, I want it to open in new window, and also tell the user its going to to do that before it does…




<?php $this->widget('bootstrap.widgets.TbNavbar', array(

    'type'=>'inverse', // null or 'inverse'

    'brand'=>'abc',

    'brandUrl'=>'/index.php',

    //'collapse'=>true, // requires bootstrap-responsive.css

    'items'=>array(

        array(

            'class'=>'bootstrap.widgets.TbMenu',

            'items'=>array(

                array('label'=>'Home', 'url'=>array('/site/index'), 'active'=>true),

                array('label'=>'abc', 'url'=>array('#'), 'items'=>array(

                    array('label'=>'def', 'items'=>array(

					    array('label'=>'Administration', 'icon'=>'icon-th-list', 'url'=>array('/leads/admin'), 'visible'=>Yii::app()->user->checkAccess('Manager') || Yii::app()->user->checkAccess('Operator')),

					    array('label'=>'Create', 'icon'=>'icon-pencil', 'url'=>array('/leads/create'), 'visible'=>Yii::app()->user->checkAccess('Manager') || Yii::app()->user->checkAccess('Operator')),

'---',

...

	



[list=1]

[*]The good news is that in HTML5 you can again use [font=“Courier New”]target="_blank"[/font] like old HTML3 times! So you can add to each relevant menu item [font=“Courier New”]‘linkOptions’ => array(‘target’ => ‘_blank’)[/font]. So no need for [font=“Courier New”]rel=“external”[/font], or at least you can combine them if you really need for semantic/whatever reason.

Anyway if you still want it, I think it’s quite easy. Just add [font=“Courier New”]‘linkOptions’ => array(‘rel’ => ‘external’)[/font] to each of the relevant menu (sub)items.

[*]See http://stackoverflow.com/questions/4111551/capture-user-leaving-page-with-jquery

[/list]

Edited to add W3’s link

hey Bennouna!

  1. Great, thanks, that did it! I might just go back to using _blank then, i dont use HTM5 yet, but I do have a script that looks for target="_blank" and replaces it with rel=“external”… on another project (non Yii and also has the "youre leaving!) popup ::) i’ll use that on Yii probably!)

  2. Saw that link on my travels, it will alert when leaving the page, but i needed it to alert when you click a link before you actually leave… I achived this with a jQuery plugin… http://rewdy.com/tools/leavenotice-jquery-plugin

p

There are some interesting points in time in this article but I don’t know if I see all of them center to heart. There is some validity but I will take hold opinion until I look into it further. Good article , thanks and we want more! Added yii.te.gd to FeedBurner as well good luck