ColeenChaos Posted May 27, 2021 Share Posted May 27, 2021 ...snip... function myFunction(){ newPageTitle="New Title"; document.title = newPageTitle; } next... title.php I have a small php script that runs a local command and outputs a simple text string. next... I run myFunction every 5 seconds. setInterval(function(){ changePageTitle(); }, 5000); The question: rather than the above function setting the page title to "New Title", how do I set it to the output of title.php? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/312799-creating-js-variable-with-php/ Share on other sites More sharing options...
dodgeitorelse3 Posted May 27, 2021 Share Posted May 27, 2021 What does title.php look like? Quote Link to comment https://forums.phpfreaks.com/topic/312799-creating-js-variable-with-php/#findComment-1586835 Share on other sites More sharing options...
requinix Posted May 27, 2021 Share Posted May 27, 2021 If title.php is the only place that knows what the new title needs to be then you'll have to make an AJAX request to it. Quote Link to comment https://forums.phpfreaks.com/topic/312799-creating-js-variable-with-php/#findComment-1586836 Share on other sites More sharing options...
ColeenChaos Posted May 27, 2021 Author Share Posted May 27, 2021 requinix. Yes. How do I form that ajax statement? Quote Link to comment https://forums.phpfreaks.com/topic/312799-creating-js-variable-with-php/#findComment-1586837 Share on other sites More sharing options...
ColeenChaos Posted May 27, 2021 Author Share Posted May 27, 2021 I figured it out: <script type="text/javascript"> function loadlink(){ $('#track').load('tracktime.php',function () { $(this).unwrap(); } ); } function changePageTitle() { newPageTitle = 'New Page Title'; $.get("tit.php", function(data){ document.title = data;}); } loadlink(); // This will run on page load setInterval(function(){ loadlink(); // this will run after every 5 seconds changePageTitle(); }, 5000); </script> Quote Link to comment https://forums.phpfreaks.com/topic/312799-creating-js-variable-with-php/#findComment-1586838 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.