I’m trying use HTML5 localStorage with a Ruby haml template and need to be able to get the value of localStorage.getItem(‘myItem’) to pass to a java applet (code stripped down):
- content_box("MyBox") do
%object{:classid => "clsid:xxx"}
%param{:name => "myItem", :value => "javascript:localStorage.getItem('myItem')"}
%comment
%EMBED{:myItem => "javascript:localStorage.getItem('myItem')"}
%noembed
Is there a good way to do this? I can do something like:
:javascript
document.write("<param name='myItem' value="+localStorage.getItem('myItem')+">"
but that’s so ugly!
Note that this is an object I’m embedding, and need the value to be present before document_ready; I cannot select the object and append the value to it on document_ready. The only other way I can think of is to do an ajax submission to make the value a Ruby variable ahead of time, but that’s really unnecessary.
Thanks!
Sometimes the only way that works is ugly.
IF your data is stored on the client, creating a server request/page/action just to get the data and pass it back in a different form straight back to the client is uncessessary, and arguably uglier.
Go with using javascript to add the
<param>tag.