0

I am calling a javascript function (function test()) which calls a url which returns a html script. I want to render that on to the page.

I am using this, but when I go to view source I am not seeing any image..

function test()
{
    document.write('<SCR'+'IPT SRC="http://demoweb.com/renderimage;type=a;num='+ 1000 +'?" type="text/javascript"></SCR'+'IPT>');
}

This retuns URL http://demoweb.com/renderimage;type=a;num=1000? (if I paste it in browser)

document.write("<img src='http://demoweb/?ct=0:abg22&adv=43nn3gg&fmt=2' width='1' height='1' border='0'/>");

1 Answer 1

1

A browser's View Source shows the HTML as-downloaded from the server, not the page's DOM after any scripts have run. For that you'd use a DOM browser, such as Firefox's DOM Inspector or Firebug, or IE's Developer Tools.

Use of document.write is not recommended because it causes a re-parse of the document. It's better to use DOM manipulation methods instead.

Try this:

var img = document.createElement("img");
img.src = "http://demoweb/?ct=0:abg22&adv=43nn3gg&fmt=2";

var imgParent = document.getElementById("whatever");
imgParent.appendChild( img );
Sign up to request clarification or add additional context in comments.

2 Comments

instead of adding it to the "whatever" image. How do I write that to body? is it just document.getElementById("body") ?
var htmlBody = document.getElementsByTagName("body")[0];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.