Scala Play framework URL in iframe is not working

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 12:17:50

问题


I want to display this iframe in my scala play view;

<iframe src="http://localhost:9020/index.html#/group/sectiona/sectionb">Loading...</iframe>

If I hard code this url, it works. But I want it to be dynamic. I tried;

  1. <iframe src="http://localhost:9020/index.html#/group/{{ 'http:\//localhost:9020\/#\/group\/' + myclass.section + '\/' + myclassb.section }}/testtopic">Loading...</iframe>
  2. <iframe src="http://localhost:9020/index.html#/group/{{myclass.section}}/sectionb">Loading...</iframe>
  3. <iframe class="graphiframe" src="{{ 'http:\//hello' + myclass.section + 'world'}}" frameborder="0" style="overflow:hidden" height="100%" width="100%">Loading...</iframe>
  4. <iframe class="graphiframe" src="{{ 'http://hello' + myclass.section + 'world'}}" frameborder="0" style="overflow:hidden" height="100%" width="100%">Loading...</iframe>

etc..

None of this works. in 4 and 5, when I inspected the element, the entire src is gone from iframe, and I got an iframe with error messages Action not found. For request 'GET /%7B%7B%20'http:///hello'%20+%20myclass.section%20+%20'world'%7D%7D' and Action not found. For request 'GET /%7B%7B%20'http://hello'%20+%20myclass.section%20+%20'world'%7D%7D' respectively. I have made changes in application.conf like play.filters.headers.frameOptions = null. It use Play 2.4.0.

How can I fix this?


回答1:


You need "the magic ‘@’ character": https://www.playframework.com/documentation/2.6.x/ScalaTemplates

so

<iframe src="http://localhost:9020/index.html#/group/{{myclass.section}}/sectionb">Loading...</iframe>

must be

<iframe src="http://localhost:9020/index.html#/group/@myclass.section/sectionb">Loading...</iframe>

or

<iframe src="http://localhost:9020/index.html#/group/@{myclass.section}/sectionb">Loading...</iframe>


来源:https://stackoverflow.com/questions/46919759/scala-play-framework-url-in-iframe-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!