[英]How do I set the name of a window in ROR?
如何在ROR中“命名”浏览器窗口,以便我可以在以后从另一个(弹出窗口)窗口打开一个页面(使用target =“name”html参数)
You have to use JavaScript for this: 你必须使用JavaScript:
<script type="text/javascript">
window.name = "MyWindow";
</script>
Of course you could easily package this up into a Rails helper method. 当然,您可以轻松地将其打包成Rails帮助程序方法。 For example, in
app/helpers/application_helper.rb
add a new method: 例如,在
app/helpers/application_helper.rb
添加一个新方法:
def window_name(name)
content_for(:window_name) do
"<script type=\"text/javascript\">window.name = \"#{name}\";</script>"
end
end
Next, in your layout file, add this line somewhere within the HTML <head>
element: 接下来,在您的布局文件中,在HTML
<head>
元素中的某处添加此行:
<%= yield :window_name %>
Finally, in your view templates, simply add a line like this (can be anywhere you want) to output the correct JavaScript: 最后,在您的视图模板中,只需添加一行(可以在任何您想要的地方)输出正确的JavaScript:
<% window_name 'MyWindow' %>
You could try below: 你可以尝试下面:
var x=window.open("", "myWindow");
var y="<head><title>my window</title></head><body>my window</body>";
x.document.write(y);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.