Jump to content

Inserting Image


rockinaway

Recommended Posts

I am trying to insert an image using a Javascript function, but I get the 'unterminated string literal' error.

 

The code I am using is:

 

javascript:doInsImg('<img src="http://example.com/tongue.gif" />');

 

But I get the error (from Firebug):

 

unterminated string literal

javascript:doInsImg('<img src=

Line 1

 

What do I do? It has something to do with the double quotes I think (").. any help?

Link to comment
Share on other sites

What is this "doInsImg" function? I don't recall ever seeing it. Anyway, from the looks of things, I assume this is being called within a HTML tag such as <a href="javascript: dosomething();">Do Something</a> right? If that is the case, I can guess on what the problem is. You see that double quotes before the http://?, that is ending the string of the attribute tag. You will need to escape it so you'll want that line to look something like:

javascript:doInsImg('<img src=\"http://example.com/tongue.gif\" />');

 

Of course, I would need to see more of the source code if that doesn't work.

Link to comment
Share on other sites

I have tried that already, it doesn't work either. I forgot to mention that this is in a PHP file :) And the HTML its are quoted in.. like they are supposed to..

 

My InsImg function is:

 


function doInsImg(img
{            
        box.open();
        box.write(img);
        box.close();  
}

 

box is defined earlier, and works with other functions, so that isn't causing the problem :)

 

Hope you can help :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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