Opening a Link in a New Window within an iFrame

后端 未结 1 704
一个人的身影
一个人的身影 2021-01-15 22:10

I`m looking to create something similar to the Digg/Stumbleupon bar that is fixed to the top of a newly opened page.

In my application I display a bunch of links to

相关标签:
1条回答
  • 2021-01-15 22:48

    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 %>" />
    
    0 讨论(0)
提交回复
热议问题