如何使用jquery将javascript代码注入iframe头部

I am trying to inject javascript code into an iframe head using jquery using the following code.

 var snippets_js='<?php echo $snippets_javascript;?>';
 var scriptjs   = document.createElement("script");
 scriptjs.type  = "text/javascript";
 scriptjs.text  = snippets_js;
 $('#iframehtml').contents().find('head').append(scriptjs);

Error I am getting is

Uncaught SyntaxError: Invalid or unexpected token

below image showing the error on line

Image

Rewrite your code to the following format:

var snippets_js= 'script_line1' +
    'script_line2' +
    'script_line3' +
    'script_line4';

Edit 2:

According to your post, just remove two ' before and after your codes:

var snippets_js=<?php echo $snippets_javascript;?>