krux / postscribe

Asynchronously write javascript, even with document.write.
MIT License
986 stars 156 forks source link

Embedding complex javascript code with error #498

Open wpresources opened 4 years ago

wpresources commented 4 years ago

I have the ad code I need to use

``<script type="text/javascript">
    atOptions = {
        'key' : 'd6e15d765cb36a1f38f2811a8d94655f',
        'format' : 'iframe',
        'height' : 90,
        'width' : 728,
        'params' : {}
    };
    document.write('<scr' + 'ipt type="text/javascript" src="http' + (location.protocol === 'https:' ? 's' : '') + '://www.highprofitnetwork.com/d6e15d765cb36a1f38f2811a8d94655f/invoke.js"></scr' + 'ipt>');
</script>

I use it as follows `

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/postscribe/2.0.8/postscribe.min.js"></script>

<div id="ad"><h5>Advertisement</h5></div>
<script type="text/javascript">
  // jQuery used as an example of delaying until load.
  $(function() {
    // Build url params and make the ad call
    var add="<script type='text\/javascript'>atOptions = {'key' : 'd6e15d765cb36a1f38f2811a8d94655f','format' : 'iframe','height' : 90,'width' : 728,'params' : {}};document.write('<scr' + 'ipt type='text\/javascript' src='http' + (location.protocol === 'https:' ? 's' : '') + ':\/\/www.highprofitnetwork.com\/d6e15d765cb36a1f38f2811a8d94655f\/invoke.js'><\/scr' + 'ipt>');<\/script>";
    postscribe('#ad', add);
  });
</script>

I got an error

Uncaught SyntaxError: missing ) after argument list
    at t._insertCursor (postscribe.min.js:10)
    at t._writeScriptToken (postscribe.min.js:10)
    at t._handleScriptToken (postscribe.min.js:10)
    at t._writeImpl (postscribe.min.js:10)
    at t.write (postscribe.min.js:10)
    at s (postscribe.min.js:10)
    at a (postscribe.min.js:10)
    at u (postscribe.min.js:10)
    at HTMLDocument.<anonymous> (index.html:10)
    at e (jquery.min.js:2)
`

It feels like it's just a fundamental error but I can't fix it Please help me fix it and give me suggestions what I need to learn so that I can fix the js embedded problems in the future.