thymeleaf javascript onload=location.href - Stack Overflow

Hopefully this is a simple syntax question:I want to create an onload statement that, when piled, will

Hopefully this is a simple syntax question:

I want to create an onload statement that, when piled, will look as follows:

<body onload="location.href='#tutanchor'">

My expression language attempt is as follows:

<body th:attr="onload='location.href='+${anchorname}">

This doesn't work because it is missing the single quotes round the anchor. But if I add additional single quotes, thymeleaf cannot parse.

Any suggestions?

Hopefully this is a simple syntax question:

I want to create an onload statement that, when piled, will look as follows:

<body onload="location.href='#tutanchor'">

My expression language attempt is as follows:

<body th:attr="onload='location.href='+${anchorname}">

This doesn't work because it is missing the single quotes round the anchor. But if I add additional single quotes, thymeleaf cannot parse.

Any suggestions?

Share Improve this question edited Aug 27, 2015 at 0:00 gilly3 91.9k26 gold badges147 silver badges179 bronze badges asked Aug 26, 2015 at 23:56 JakeJake 4,68010 gold badges43 silver badges89 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

How about using &apos;?

<body th:attr="onload='location.href=&apos;'+${anchorname}+'&apos;'">

I'm not familiar with thymeleaf, so this may not work as I expect. The documentation suggests that \ is the escape character for quotes. If &apos; doesn't work, try escaping the quotes:

<body th:attr="onload='location.href=\''+${anchorname}+'\''">

It begs the question, why not just use a <script> tag?

<script th:inline="javascript">
/*<![CDATA[*/
    location.href = /*[[${anchorname}]]*/ '#';
/*]]>*/
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745542987a4632213.html

相关推荐

  • thymeleaf javascript onload=location.href - Stack Overflow

    Hopefully this is a simple syntax question:I want to create an onload statement that, when piled, will

    3天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信