Mustaasam Saleem Mustaasam Saleem - 6 months ago 6x
Javascript Question

JavaScript Function Parameter - Syntax Error

This code is working fine. But, I just want to remove variable

in third line and write direct
. Need corrected syntax of below code please. Quotes are so messy! I know there is just a little mistake. But didn't figure out.

website: function() {
var url = '';
this.echo('<a onclick="openHTTP(\''+url+'\')" href=""> My Website </a>', {raw:true});


You'll want to only replace the delimiting quotations (those ending and starting string literals) as well as +url+.

this.echo('<a onclick="openHTTP(\'\')"  href=""> My Website </a>', {raw:true});

Noting that your current snippet concatenates 2 literals and a variable:

  • '<a onclick="openHTTP(\''
  • url
  • '\')" href=""> My Website </a>'

The escaped quotations should be kept for the client-side code. They'll allow the browser to understand as a string literal. The \ will be removed by the parser, so the output includes:

<a onclick="openHTTP('')"  href="">