1

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?

5
  • Stringception. Sorry, try using &quot; Commented Dec 4, 2011 at 18:47
  • 2
    Embedding HTML like that is really horrid. Why not embed some data instead (like perhaps just images/junk1.php) and let a script take care of the rest of the content generation? Commented Dec 4, 2011 at 18:49
  • 1
    +1000 to @Tomalak's comment. Commented Dec 4, 2011 at 19:00
  • No idea of what Tomalak's talking about. I know it's horrid. I've taken like 3 classes of php, I don't know much about this, and I need this for a test, that's all. Commented Dec 4, 2011 at 19:52
  • 1
    This question is similar to: How do I properly escape quotes inside HTML attributes?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Jan 7 at 8:00

2 Answers 2

1

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

Comments

0

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>

2 Comments

Your answer would be OK if you replace \" with &quot; (<---Answer to question here).
ahh, i see your solution is probably better.

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.