2011-12-12 53 views
1

在同一窗口中的新選項卡在我的項目,我想re-open a new tab using ruby code。當用戶點擊附件鏈接時,該pdf應該在同一個窗口的新標籤中打開。我嘗試了很多,但我沒有辦法解決它。請指導我。ROR +重新打開使用Ruby代碼

回答

2

我不知道這是否可能使用紅寶石,因爲它與UI的部分交易。這確實使用HTML和Jquery非常有可能。

您可以簡單地將超鏈接中的target屬性設置爲空白,重定向至PDF並且它將在新選項卡中打開該文件。一些與此類似:

<a href="http://www.mysite.com/files/xyz.pdf" target="_blank"> 

如果你想使用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; 
    } 
    }); 
}); 
+0

謝謝老闆! – Rubyist