Jump to content

creating js variable with php


ColeenChaos
 Share

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

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

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