Mariana Gatos
Mariana Gatos

Reputation: 11

Javascript string within a string

I'm very new to this, so I'm sorry if I cant explain myself properly. I'm running a website with a lightbox for images, inside the lightbox I embeded a link and what I want to do is that link to open a new pop-up window, but I've encountered a small problem on my code:

<a href="images/gallery/1.jpg" class="lytebox" data-title="<br /><a href='javascript:popUp('images/junk1.php')'/>Add a Comment</a>">
    <img src="images/thumbnails/1.jpg" border="0">
</a>

You see, when I get to the 'javascript:popUp('images/junk1.php')' I've already used the apostrophes, so it doesn't load. I've been reading about strings being within strings and I've tried escaping it via \ but it doesn't work. Any help?

Upvotes: 1

Views: 322

Answers (2)

rlemon
rlemon

Reputation: 17667

ok.. how about you just change the call around a little.. not sure if this will work, but you could give it a try.

<a href="images/gallery/1.jpg" class="lytebox" data-title="<br /><a data-img='images/junk1.php' onclick='popUp(this.dataset.img)'/>Add a Comment</a>"><img src="images/thumbnails/1.jpg" border="0"></a>

or you can do as rob suggests...

<a href="images/gallery/1.jpg" class="lytebox" data-title="<br /><a href='javascript:popUp(&quot;images/junk1.php&quot;)'/>Add a Comment</a>">
    <img src="images/thumbnails/1.jpg" border="0">
</a>

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 360056

Use HTML entities. Something like this (not tested):

data-title="&lt;br /&gt;&lt;a href=&quot;javascript:popUp('images/junk1.php')&quot;/&gt;Add a Comment&lt;/a&gt;"

Upvotes: 1

Related Questions