I’m trying to accomplish this in Shopify.
If the user has the browser tab active (change the page title to message A) and if the tab is not active (change page title to show message B).
For some reason, something is missing or wrong in my code.
I’m inserting this code in the header of the file: theme.liquid
<script>
$(function () {
leftTitle = 'Message A';
backTitle = 'Message B';
$(window).blur(function () {
page.title = leftTitle;
});
$(window).focus(function () {
page.title = backTitle;
});
});
</script>
Any advice?
2
Answers
I found the solution myself:
I think you’re trying to use
document.title = leftTitle;
anddocument.title = backTitle;
page
doesn’t exist natively on browsers, unless you’ve declared it before, sopage.title
doesn’t change anything; it should give you a console error.