this is a duplicate of Executing groovy statements in JavaScript sources in Grails
with a slight variation, my intention is to only render the js-code without enclosing it in script tags
picture someone loading a script from my server within their html like
<script type="text/javascript" src="mywebsite.com/xyJs/xyz"></script>
and I aim to display the "content" of that request
in the controller, I analyze the /xyz
and determine what should be inside the script along with an absolute link for the iframe's src attribute.
I also need to execute this groovy script.
I'm attempting to achieve this as follows:
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>');"
however, the browser simply disregards the document.writeln('
and interprets the iframe as an HTML element, rendering its content.
how can I specify that it's just a small snippet of js-code without wrapping it in script tags?
I have also attempted to render a view like so:
render(view:'SuperStuff',model:[profil:profil])
and inside the 'SuperStuff' view is:
<%@ 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>");
unfortunately, this approach also fails and displays the content of the iframe's src. What am I doing wrong?
any guidance on this issue would be greatly appreciated, thank you in advance.