1

I am building Login page with Spring boot and thymeleaf. I pass the opcode using model attribute. And I want to use it for th:if to make condition to call javascript function automatically(meaning : without any click). Here is my code under.

<a th:if="${opcode == 1}" th:href="'javascript:setlocation()'"></a>

<script>
    function setlocation(){
        var msg = alert('Loss of location information found. Turning into setting page...');
        location.href='/setlocation';
    }
</script>

1 Answer 1

3

Put the th:if on the script itself. For example:

<script th:if="${opcode == 1}">
    alert('Loss of location information found. Turning into setting page...');
    location.href='/setlocation';
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

OMG so easy ? So <a> tag can be delete if I implement that right?
Yep, you can remove the <a> tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.