在iFrame中的新窗口中打开链接 [英] Opening a Link in a New Window within an iFrame

查看:342
本文介绍了在iFrame中的新窗口中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找类似于固定在新打开页面顶部的Digg / Stumbleupon栏的东西。

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 external sites. No when someone clicks one of them, I would want to them to be opened within a new tab with my logo/bar up top of the page.

我认为这可以使用iframe来完成。

I would assume that this can be done using iframes.

但是我不知道传递iframe src的URL参数最简单的方法是什么将被渲染到新标签上。

However I don`t know what would be the easiest way to pass the URL parameter for iframe src to be rendered onto the new tab.

非常感谢任何反馈。

推荐答案

您必须将链接指向Rails操作,并将外部URL作为参数传递。

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

所以代替:

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

您可以链接到:

 = 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

并呈现包含工具栏和iframe的HTML:

And render the HTML containing your toolbar and iframe:

<div id="toolbar" />
<iframe src="<%= @url %>" />

这篇关于在iFrame中的新窗口中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆