Problem with JS code (Uncaught SyntaxError: missing) after argument list)

2

Well, I have a code from a pop-up chatbox, but it is giving the following error:

  

Uncaught SyntaxError: missing) after argument list

Code:

 //Variáveis a editar
var imagen_chatbox_desplegable = "http://i45.servimg.com/u/f45/17/45/19/77/chat10.png";
var posicion_chatbox_desplegable = "derecha"; // ou 'izquierda'
//Fim das variáveis a editar

document.write("<div id="chatbox_ret_cont" class="chatbox_" + posicion_chatbox_desplegable + "">");
document.write("    <div onclick="(document.getElementById('chatbox_ret').style.display=='block')?my_setcookie('chatbox_ret','0',0,0):my_setcookie('chatbox_ret','1',1,0); jQuery('#chatbox_ret').toggle('normal');">");
document.write("        <span id="chatbox_ret_online">");
document.write("            <img title="Abrir e fechar o chatbox" src="" + imagen_chatbox_desplegable + "">");
document.write("        <\/span>");
document.write("        <span id="chatbox_ret_offline"><\/span>");
document.write("    <\/div>");
document.write("    <iframe src="\/chatbox" id="chatbox_ret" name="chatbox_ret" ");
document.write("       scrolling="no" frameborder="0" marginwidth="0" marginheight="1px"");
document.write("       onload="if(cb_new){cb_start();cb_new=0;}">");
document.write("    <\/iframe>");
document.write("<\/div>");
    
asked by anonymous 16.09.2015 / 16:26

1 answer

6

You must escape the double quotation marks within a string of double quotation marks, for example:

"\"string dentro de uma string\""

Then in your code:

document.write("<div id="chatbox_ret_cont" class="chatbox_" + posicion_chatbox_desplegable + "">");

You have to stay:

document.write("<div id=\"chatbox_ret_cont\" class=\"chatbox_" + posicion_chatbox_desplegable + "\">");

You can also swap in single quotation marks:

document.write('<div id="chatbox_ret_cont"></div>');

About using the document.write() method, we do not recommend using it, because any other content already created in the document will be erased. If you're even using jQuery create this html in a string and use append() to create the structure in the DOM.

    
16.09.2015 / 16:31