2

I am having trouble with this markup i programmatically insert into an editor. I don't know how to add the target="_blank" attribute. I can't get it to work even tho i tried '" "' or "' "' and all sort of combinations. I don't know what this task i called either so i can't really google it. Any help would be appreciated to make this work

var html = "<a href='" + host + "/draught/connect/Download" + draughtDownloadType + "?PropId=" + selectedPropertyId + autoUpdateQuery + "' target=_blank>" + linkText + "</a>";

3 Answers 3

2

You need to escape the " character by placing a \ infront of it.

target=\"_blank\"

To give you:

var html = "<a href='" + host + "/draught/connect/Download" + draughtDownloadType + "?PropId=" + selectedPropertyId + autoUpdateQuery + "' target=\"_blank\">" + linkText + "</a>";
Sign up to request clarification or add additional context in comments.

2 Comments

thank you! This worked perfectly. That is exactly what i wanted to do. But i didn't know it was called escape so i couldn't google it :)
No worries @Phil_TheAverage - searching for syntax is always hard!
0

use escape

var html = "<a href='" + host + "/draught/connect/Download" + draughtDownloadType + "?PropId=" + selectedPropertyId + autoUpdateQuery + "' target=\"_blank\">" + linkText + "</a>";

Comments

0

You can use target='_blank'. In JS while doing concatenation then you can use ' inside "" without any issue and vice-versa.

Comments

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.