Remove script tags from inside title tag

Hi

i want to display only the value of “geturl” in inside < title > tag

But below code displays the < script > tags also inside < title > tag

<title>
<script type="text/javascript">
var geturl = window.location.pathname;
document.write(geturl);
</script>
</title>

how can i only display value of variable and leave out the script tags inside < title > tag

vineet

Script blocks should not be inside the <title>. If you want to change the title of the site, this can be done like e.g.

document.title = window.location.pathname;

in a usual script block in the head or body.

hi m3g4p0p

Its showing the variable value in the browser correctly.

But when i see the content of “view-source” of page then the title tag is empty.

Will the seo bots be able to see the title tag content and accept the title tags content from inside javascript like we just did ??

vineet

As long as they have JavaScript enabled, sure.

1 Like

thanks Mittineague for the clarification

vineet

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.