3

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});
2
  • 1
    this.echo? i am confused. Please paste full code along with expected outcome Commented Apr 23, 2016 at 22:04
  • Mistakenly added @JonathanLonowski Commented Apr 23, 2016 at 22:38

3 Answers 3

6

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="">
Sign up to request clarification or add additional context in comments.

2 Comments

@JonathanLonowski solved it correctly. Marked as correct answer.
I am waiting for OP's response. removed my -ve mark
4
website: function() {
        this.echo('<a onclick="openHTTP(\'http://www.google.com\')"  href=""> My Website </a>', {raw:true})
    }

please try this one

Comments

4

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

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

1 Comment

just replace "url" variable with "www.google.com". This will Work fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.