Opening a Link in a New Window within an iFrame

前提是你 提交于 2019-12-01 12:11:17

You'll have to point your links to a Rails action, passing the external URL as a parameter.

So instead of:

 = link_to "http://rubyonrails.org/"
 # => <a href="http://rubyonrails.org/">

You would link to:

 = link_to open_url_path, url: "http://rubyonrails.org/"
 # => <a href="/open_url?url=http%3A%2F%2Frubyonrails.org%2F">

Then you can pass the url from your controller to the view:

def open_url
  @url = params[:url]
end

And render the HTML containing your toolbar and iframe:

<div id="toolbar" />
<iframe src="<%= @url %>" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!