-1

Im coding a Chrome extension and tried injecting some code like this:

var actualCode = ['$("a").unbind("click");'].join('\n');

var script = document.createElement('script');
script.textContent = actualCode;
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);

I have the code from this question

The problem is that I have to use double quotes which relates to a right click from the context menu, so the code become:

 Injecting-Code: "var actualCode = ['$("a").unbind("click");'].join('\n');"

How do I handle the double quotes in my Jquery: $("a").unbind("click");

Note : I tried escaping them like this \" but it doesnt work

Community
  • 1
  • 1
Youss
  • 4,196
  • 12
  • 55
  • 109
  • Where does this `Injecting-Code` message come from? Looks like it's just the output there that is not properly escaped. – Bergi May 20 '15 at 06:48
  • Injecting-Code is part of a function which I need to inject the code into website – Youss May 20 '15 at 06:55
  • 1
    Please show us that function. `console.log` for example is known to not escape anything in a string, but just place quotes around it. – Bergi May 20 '15 at 06:57
  • @Bergi Im at work and I have the code home...sorry, but its just a simple function nothing fancy. I really think the double quotes are the problem, because the error messages from console where pointing to the beginning of double quotes – Youss May 20 '15 at 07:04

1 Answers1

-1

['$("a").unbind("click");'].join('\n') this technique is used when you have multiple lines of code.

you better use this
var actualCode = '$("a").unbind("click");';

This should solve your problem. Let me know if this helps.

Kishor Pawar
  • 3,386
  • 3
  • 28
  • 61