Jump to content

Recommended Posts

...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.


 

Link to comment
https://forums.phpfreaks.com/topic/312799-creating-js-variable-with-php/
Share on other sites

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.