开发者

How can I insert a <script type='text/javascript' src=''> tag on a 3rd party webpage using rails?

The question alone could be a little confusing so here's a brief explanation:

I want to give 3rd parties a javascript call example: <script type='text/javascript' src='http://myrailswebsite.com/controller/action?params'> using which they can call a action with a few params on my rails server. My action after evaluating the params should insert another <script type='text/javascrtipt' src='http://my_partner_site.com/xxx.php?evaluated_params'> tag into the 3rd party's webpage which should get evaluated while the page completes loading.

I have tried using

    def action
      #<evaluate params...snipp开发者_运维百科ed for clarity>
      render :update |page|
        page << "<script type='text/javascript' src=...>"
      end
    end

But I get an error in firebug saying "missing } in XML expression" which is due to the try catch block which rails puts around the script tag and parser thinking that this is an xml expression. I can't rely on 3rd party websites I am integrating with to have prototype.js included.

I have tried other options like rjs and respond_to format.js as well but no luck. Please help.


Try doing:

def action
  #<evaluate params...snipped for clarity>
  render :update |page|
    page << "document.write(\"<script type='text/javascript' src=...>\");"
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜