I use some Facebook JS scripts for user authentification, etc. I want to place them in the properly unobtrusive way as application-wide scripts.
Currently I have the script as a partial and call it from my application header:
<%# render 'layouts/facebook_app_scripts' %>
The script works but is extremely obtrusive. I want to make it unobtrusive. This is especially important since I tap into all sorts of APIs and it's getting messy.
You don't need to see it in its entirety (if you need to see the script to answer this question, I don't think you'll be any help as this is a general question not script-specific)
You should know that it contains dynamically created links such as this one:
window.top.location = "<%= Facebook::SITE_URL.to_s %>/logout";
That means that putting this in a .js file in the assets/javascript folder isn't going to work, since .js files can't access rails-generated variables.
So how can I shift my javascript with dynamically-generated links from the rails view to an unobtrusive javascript file?
看一下这个项目 ,将所有Facebook JS SDK都包含在内
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.