1

这是在 Grails 的 JavaScript 源代码中执行 groovy 语句的副本

有一个区别,我只想渲染 js 代码,周围没有脚本标签

想象有人在他的 html 中从我的服务器加载一个脚本,比如

<script type="text/javascript" src="mywebsite.com/xyJs/xyz"></script>

我想呈现请求的“内容”

在控制器内部,我解析/xyz并找出脚本中必须包含的内容以及 iframe src 的绝对链接我也需要运行这个 groovy 脚本我正在尝试这样做

    render "document.writeln('<iframe src=\"${grailsApplication.config.grails.serverURL}/superStuff/stuff23/${profil.slugs}\" name=\"SuperStuff\" width=\"300\" height=\"600\" align=\"left\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" ></iframe>');"

但浏览器只是忽略document.writeln(' 并将 iframe 视为 html 元素并呈现其内容

我怎么能在不设置脚本标签的情况下定义它只是一点点 js 代码?

我也试图渲染一个像

render(view:'SuperStuff',model:[profil:profil])

在视图里面 SuperStuff 是

<%@ page contentType="text/javascript; UTF-8" %>
document.writeln("<iframe src='${grailsApplication.config.grails.serverURL}/superStuff/stuff23/${profil.slugs}' name='SuperStuff' width='300' height='600' align='left' scrolling='no' marginheight='0' marginwidth='0' frameborder='0' ></iframe>");

但这也不起作用并呈现 iframe 的 src 的内容我做错了什么?

对于任何提示,这让我很模糊,提前谢谢

4

2 回答 2

1

是的,把那个修好了

render contentType: 'text/javascript', text: "document.writeln('<iframe src=\"${grailsApp......."
于 2013-04-26T10:50:15.763 回答
0

I believe, your controller works just as expected: it returns the javascript-code exactly as you want: your call to document.writeln(). Please use the Network-Panel of Firebug, Chrome DevTools or similar to verify this.

However, the js-code will immediately be executed which results in the inclusion of the specified iframe-element on the current position, as explained for example here.

于 2013-04-26T07:29:11.603 回答