• I’m trying to figure out how to auto refresh an image in a post without refreshing entire page. The image is from a webcam that uploads to server via ftp.

    I’ve tried using a few googles java scripts, but I don’t know much about it and they didn’t seem to work.

    Is there a plugin for webcams? Or does someone have a script that works in a wordpress page/post?

Viewing 5 replies - 1 through 5 (of 5 total)
  • I have my webcam working in a WP page. My script is based on one that came with Webcam32, and actually pulls the image from the camera rather than from the server, but it should work well enough.

    My page contains this:

    <script type="text/javascript" src="/path/cam.js"></script>
    <img src="/path to image" class="centered" alt="This is me" id="imagename" width="320" height="240" />
    <script type="text/javascript">initialImage();</script>

    The script looks like this:

    newImage = new Image();

    function loadNewImage(){
    uniq = new Date();
    uniq = uniq.getTime();
    document.images.imagename.src=newImage.src;
    newImage.src="https://<path to your image>?"+uniq;
    }

    function initialImage(){
    uniq = new Date();
    uniq = uniq.getTime();
    newImage.onload=loadNewImage;
    newImage.src="https://<path to your image>?"+uniq;
    }

    function imageError()
    {
    image = document.images.imagename;
    image.onload = "";
    image.onerror = "";
    startstop.disabled = true;
    document.images.imagename.src = "https://<path to default image>";
    }

    This version loads the image as normal, then immediately tries to reload it. The odd stuff with the ?uniq forces the browser to fetch the image rather than taking it from the cache.

    EDIT: This could be adapted to pause for a short time before refreshing, depending on how often your FTP process happens.

    Thread Starter kismet78

    (@kismet78)

    Wow, I’ll give that a shot, but to be honest I really have no clue how to implement that…

    * After giving it a shot – it seemed to work for about 3 seconds and then nothing? I saw the clock caption commencing. Am I doing something wrong?

    https://www.kyletompkins.com/wp/?page_id=60

    Thread Starter kismet78

    (@kismet78)

    This is what my .js looks like. Am I close?

    newImage = new Image();

    function loadNewImage(){
    uniq = new Date();
    uniq = uniq.getTime();
    document.images.imagename.src=newImage.src;
    newImage.src=”https://www.kyletompkins.com/wp/webcam/capture1.jpg?”+uniq;
    }

    function initialImage(){
    uniq = new Date();
    uniq = uniq.getTime();
    newImage.onload=loadNewImage;
    newImage.src=”https://www.kyletompkins.com/wp/webcam/capture1.jpg?”+uniq;
    }

    function imageError()
    {
    image = document.images.imagename;
    image.onload = “”;
    image.onerror = “”;
    startstop.disabled = true;
    document.images.lescam.src = “https://www.kyletompkins.com/wp/webcam/capture1.jpg?&#8221;;
    }

    Thread Starter kismet78

    (@kismet78)

    Still no luck yet…

    I’ll keep trying to tweak this, but does anyone else have anything for me to try?

    Cheers.
    kyletompkins.com

    I’ll have a look at this later – I’ve got other people working, shouldn’t be a problem with yours.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘auto refresh just image’ is closed to new replies.