I need to convert a rails 2.3 site so that all external URLs open in a new window. I could go though every call to link_to
and add :target => \'_blank\'>
You should not have to change your server-side code for this view problem.
You should use Unobscursive javascript. This example will only make external links showing up in a new window :
// jQuery
//
$(document).ready(function() {
$("a").click(function() {
link_host = this.href.split("/")[2];
document_host = document.location.href.split("/")[2];
if (link_host != document_host) {
window.open(this.href);
return false;
}
});
});