How to set window name in ROR?

How can I β€œname” a browser window in ROR so that I can subsequently open a page in it from another (pop-up) window (using the target = "name" html parameter)

+4
source share
2 answers

To do this, you need to use JavaScript:

<script type="text/javascript"> window.name = "MyWindow"; </script> 

Of course, you can easily pack this into the Rails helper method. For example, in app/helpers/application_helper.rb add a new method:

 def window_name(name) content_for(:window_name) do "<script type=\"text/javascript\">window.name = \"#{name}\";</script>" end end 

Then in your layout file, add this line somewhere inside the HTML <head> element:

 <%= yield :window_name %> 

Finally, in your view templates, simply add a line like this (maybe anywhere) to display the correct JavaScript:

 <% window_name 'MyWindow' %> 
+5
source

You can try the following:

 var x=window.open("", "myWindow"); var y="<head><title>my window</title></head><body>my window</body>"; x.document.write(y); 
0
source

Source: https://habr.com/ru/post/1276494/


All Articles