Alex Borsody
Alex Borsody

Reputation: 2040

syntax issue: printing a link with variables

I want to print this

<link rel="canonical" href="http://nyc.mymusicwebsite.com/coolband/1222
"/>

where

var termsText = nyc
var deliurl = http://nyc.mymagazine.com/coolband/122
deliurl2[1] = mymagazine
deliurl[2] = .com/coolband/122

(deliurl is split at .) I have this code so far which almost works, This is the problem

document.write('<link rel=cononical"'+" ""href="http:"//"""+termsText+"."+deliurl2[1]+deliUrl[2]'"/>');

my biggest problem is printing " for the href

Upvotes: 0

Views: 60

Answers (2)

Paul
Paul

Reputation: 141827

document.write('<link rel="cononical"'+' href="http://'+termsText+'.'+deliurl2[1]+deliUrl[2]+'" />');

Upvotes: 1

user229044
user229044

Reputation: 239311

That isn't how you escape double-quotes in JavaScript. Use "\"":

"This is a string \"full\" of \"scare quotes\".";

or alternate between single and double quotes:

'This string can "contain" unescaped "double quotes".'

Upvotes: 2

Related Questions