Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7501057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:24:31+00:00 2026-05-29T20:24:31+00:00

I wrote one script which gets an image url through JSONP, and then I

  • 0

I wrote one script which gets an image url through JSONP, and then I needed to write that to browser, this is a status image which is onling.png, offline.png and so on

my script looks like this.

<div id='STATUSDIV'></div>
    <script language=javacsript type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js></script>
    <script type="text/javascript">$(document).ready(function()
    { 
        $.getJSON('http://MYSSERVERNAME.COM/get.php?callback=?','q=value&index'+Math.random(),
        function(res)
        { 
            document.getElementById('STATUSDIV').innerHTML = ("<img src='"+res.img+"' />");
        });
    });
    </script>

using this code, I am able to get an image inside div statusdiv, however I can not use same code block twice on single page as both will point to same div.

quick thing I can do is that I can ask end user who will copy this code multiple time on each page to change div id so that that image will load on differnt div.

But I wanted to have same code wherever copied just writes image inline. kind of createelement and write in that element. but thats not working. document.write does not work either as it replaces everything.

Is there a way that when this code block called, Instead of writing innerhtml, code creates a dynamic div right there on the page and writes image in that. and this image writing and creating div happens where script block is called. so that If same script is called in header and footer, status image will appear on both header and footer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:24:34+00:00Added an answer on May 29, 2026 at 8:24 pm

    The cleanest way I know of is to create a function for your code that should get included very early in the page so it’s available everywhere:

    function insertStatusHere() {
        var thisId = "status" + insertStatusHere.myDivCntr++;
        document.write('<div class="statusContainer" id="' + thisId + '"></div>');
        $(document).ready(function() {
            $.getJSON('http://MYSSERVERNAME.COM/get.php?callback=?','q=value&index'+Math.random(), function(res) { 
                document.getElementById(thisId).innerHTML = ("<img src='"+res.img+"' />");
            });
        });
    }
    insertStatusHere.myDivCntr = 0;
    

    Then, any place in the page where someone wants a status image, they can put this inline script:

    <script type="text/javascript">
    insertStatusHere();
    </script>
    

    This dynamically inserts a div with a unique div ID at the place that the function call is made and it keeps track of each ID that is used in the closure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to write a one-line Perl script that will toggle a line
How would one write a sql server DDL script that can: For each table
So I have a script that gets passed a URL as a get param,
I was inspired by another question to write a script (or rather a one-liner)
I recently found out about C# extension methods and wrote this one: /// <summary>
One of my coworkers wrote a .NET windows service that converts .doc to .docx
I wrote a simple CMS for one of my clients which does specifically what
I wrote a program out, which was all in one file, and the methods
I have a quite simple perl script, that in one function does the following:
I wrote a MATLAB script with gui which I also want to let my-coworkers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.