How to update an image src without JavaScript?

Posted on 2007-10-04
Last Modified: 2013-11-19
I've implemented 1x1 pixel tracking by adding an onclick event to all links - the onclick event updates a 1x1 pixel.  My question is:

can I update a loaded image's src without javascript?
Question by:InsertCleverName
    LVL 1

    Accepted Solution

    The short answer is no, you can't. To dynamically change an image element's src attribute after the page loads, you have to use some sort of scripting language, such as JavaScript or VBScript.

    If you explain more about what you're trying to do however, perhaps someone can suggest an alternative implementation.

    Note that you can do certain dynamic things using just CSS. For example, IE7, Firefox, and many other browsers support the CSS :hover, :active, and :focus pseudo-classes, which you could use to change the background-image style attribute, for example.
    LVL 5

    Expert Comment

    Using AJAX you will update the image but AJAX is also a script function..
    LVL 1

    Expert Comment

    Ajax, which stands for Asynchronous JavaScript and XML / XMLHttpRequest is not a scripting language at all, but merely a technique or collection of technologies. You can't technically use Ajax to update the page... You use XMLHttpRequest to exchange data asynchronously with the web server, and JavaScript to process the response and update the DOM.

    Author Comment


    Thanks for the comments.  I'm trying to update a 1x1 pixel, that belongs to another site, when someone clicks on certain links on my site and then send the clicker to the URL associated with the link.  This works fine, but I see in my logs that ~5-10% of clicks aren't updating the pixel and I assume the users have JavaScript disabled.

    Sounds like I have to sync with the owner of the 1x1 pixel and send them a final redirect URL. So a click on my site first redirects to the address the 1x1 pixel uses currently and then the address at the 1x1 pixel will redirect to the final URL I provide.

    Any other suggestions?

    Author Comment

    To clarify, each link that updates the 1x1 pixel will update the 1x1 pixel with a unique src/URL.  Each link has a different cost-per-click associated with it and I'm sending the cost-per-click info to the 1x1 pixel.
    LVL 54

    Expert Comment

    You might want to clarify what you are trying to do and what the issue is.  I am afraid I am still a little confused despite the details you provided.  The first comment by Steve answered your main question.  His follow up on AJAX is right too.

    I would add one small thing.  If the link uses onclick (or any event) and not the href attribute then you are dependent on client side script.  On its own that event is nothing without script being called.  If you are getting charged for every click, even if the script isn't working like you think, then Javascript isn't completely disabled.  Nothing would happen at all when Javascript is disabled (assuming the href is just like this href="#").  The issue might really be in some other part of this tracking process.

    If you still need help with this then you might want to elaborate on what you need and what is going on.  I hope this info and the questions will help you know what to provide and explain the basics of what is happening.  You really did get the answer in the first comment so if you want to start a new one for a follow up issue then you can post the URL of that question here.

    Let me know if you have a question or need more info.


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Read about why website design really matters in today's demanding market.
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now