Permalink
Browse files

Merge pull request #1 from Magicdream/master

Add javascript response for redirect_from_iframe method
  • Loading branch information...
2 parents 4ceefc4 + c677a4c commit 16d8ea61e8ce1bead24afd1169e3dee17de3e347 @dekart committed Feb 27, 2012
Showing with 24 additions and 6 deletions.
  1. +24 −6 lib/facepalm/rails/controller/redirects.rb
@@ -23,11 +23,22 @@ def redirect_from_iframe(url_options)
redirect_url = url_options.is_a?(String) ? url_options : url_for(url_options)
logger.info "Redirecting from IFRAME to #{ redirect_url }"
-
- render(
- :text => iframe_redirect_code(redirect_url),
- :layout => false
- )
+
+ respond_to do |format|
+ format.html do
+ render(
+ :text => iframe_redirect_html_code(redirect_url),
+ :layout => false
+ )
+ end
+
+ format.js do
+ render(
+ :text => iframe_redirect_js_code(redirect_url),
+ :layout => false
+ )
+ end
+ end
end
# Generates HTML and JavaScript code to redirect user with top frame location
@@ -36,7 +47,7 @@ def redirect_from_iframe(url_options)
# @param target_url An URL to redirect the user to
# @param custom_code A custom HTML code to insert into the result document.
# Can be used to add OpenGraph tags to redirect page code.
- def iframe_redirect_code(target_url, custom_code = nil)
+ def iframe_redirect_html_code(target_url, custom_code = nil)
%{
<html><head>
<script type="text/javascript">
@@ -50,6 +61,13 @@ def iframe_redirect_code(target_url, custom_code = nil)
</head></html>
}
end
+
+ # Generates JavaScript code to redirect user
+ #
+ # @param target_url An URL to redirect the user to
+ def iframe_redirect_js_code(target_url)
+ "window.top.location.href = #{ target_url.to_json };"
+ end
end
end
end

0 comments on commit 16d8ea6

Please sign in to comment.