Reputation:
I have a website that has a <title>
tag that is something like this: <title>Blog post name → Site.com</title>
and I want the first part of it to be displayed.
So I want only the Blog post name
to be displayed. Here is what I did to display the whole title:
Text blah blah blah: <script>document.write(document.title);</script> blah blah blah.
Is there a way I can do this? Thanks!
Upvotes: 1
Views: 1281
Reputation: 62831
Another approach would be to use indexOf
and substring
:
<script>document.write(document.title.substring(0, document.title.indexOf('&rarr')));</script>
Here is the Fiddle.
Upvotes: 1
Reputation: 1129
Make a split on the document.title
to get the first part.
All other things can be left unchanged.
<script>document.write(document.title.split("\u2192")[0]);</script>
\u2192
is the code for the &raar;
character
Upvotes: 2