Mustaasam Saleem
Mustaasam Saleem

Reputation: 166

JavaScript Function Parameter - Syntax Error

This code is working fine. But, I just want to remove variable url in third line and write direct www.google.com. 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 = 'www.google.com';             
this.echo('<a onclick="openHTTP(\''+url+'\')"  href=""> My Website </a>', {raw:true});

Upvotes: 3

Views: 80

Answers (3)

Jonathan Lonowski
Jonathan Lonowski

Reputation: 123453

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

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

Noting that your current snippet concatenates 2 literals with the variable:

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

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

<a onclick="openHTTP('www.google.com')"  href="">

Upvotes: 6

Hamza Hafeez
Hamza Hafeez

Reputation: 115

just replace "url" variable with "www.google.com"

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

Upvotes: 4

Michal Tinka
Michal Tinka

Reputation: 165

website: function() {
        this.echo('<a onclick="openHTTP(\'http://www.google.com\')"  href=""> My Website </a>', {raw:true})
    }

please try this one

Upvotes: 4

Related Questions