Scala Play framework URL in iframe is not working

2019-08-07 14:02发布

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条回答
欢心
2楼-- · 2019-08-07 14:59

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>
查看更多
登录 后发表回答