I found good solution for this.
<script> var url = window.location.href; url_parts = url.split('/'); <script>
Then I changes the code as follows which works fine for me.
<script> var url = window.location.href; var url_parts; url = url.toString(); url_parts = url.split('/'); <script>
Happy Coding !!