0

On a "normal" html.erb view I run js code on page load by including something like this in application.js

$(window).on('load', function() {
   $("#yield_wrap").css({"opacity":"1"});
});

How can I accomplish something similar when the page/content is loaded by a javascript-view (e.g. show.js.erb)?

Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232

1 Answers1

0

Unless I misunderstand your question completely, the show.js.erb will just contain the javascript that is executed in the browser. You do not have to wait for an event.

nathanvda
  • 49,707
  • 13
  • 117
  • 139
  • And if I want to run something on what the `show.js.erb` has rendered? I need to truncate some text (client-side), but need the page (including web-fonts) to load completely first. – Fellow Stranger Sep 17 '13 at 11:48
  • I would assume that the webfonts would be loaded already, or are you adding new webfonts through ajax? You need the rendered size to be able to correctly get the width of the text? If that is the case, I wuld suggest changing the following answer: http://stackoverflow.com/questions/4488874/jquery-event-for-when-ajax-loaded-content-is-all-loaded-including-images – nathanvda Sep 17 '13 at 12:18