在IFRAME斯卡拉剧框架URL不工作(Scala Play framework URL in if

2019-09-28 09:10发布

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?

Answer 1:

你需要“神奇‘@’字符”: https://www.playframework.com/documentation/2.6.x/ScalaTemplates

所以

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

一定是

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

要么

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


文章来源: Scala Play framework URL in iframe is not working