Quote (single quote) inside quotes in javascript and php

Asked

Viewed 964 times

0

I wanted a more elegant way to write the code below. He is passing the parameters via GET but goes with ' and I can even use a PHP function of replace but wanted a solution without gambiarra. Note that it is ' inside ' then I put ' but it goes in the parameter and I put " php does not work. Follow the code

onClick=\"window.parent.document.getElementById('webcam_show').src='webcam_html5/index.php?text_area=\'ta_proprietario_altera_foto64\'&frame_destino=\'frame_proprietario_foto_altera\'';window.parent.div_mostra('webcam')\"
  • There’s nothing wrong with escaping a string

  • Blza, I even agree that it wouldn’t be the end of the world, but I’m really bored with this project, I was wondering if there’s a way not to do this. thanks.

  • 1

    Can you post more of your code, from the variable that receives the string you want to escape? The way it is, I confess that for me, it’s a little hard to understand

  • but pq that ' on the line? If it is in php it is not necessary. The value of the variable does not need quotes. But if, however, you still want to put simple quotes replace ' with ". Chr(39)." Here’s how it looks: ..... index.php? text_area=". Chr(39)." ta_proprietario_altera_foto64". Chr(39)." &frame_destination ..... But the best thing is to answer Marceloboni’s request so that we can answer with certainty.

  • the ' on the line appears as I cannot pass a text parameter via get without quotation marks. Thanks for the help, it seems a good solution.

1 answer

1

One possibility would be to move the code to a function.

That way your HTML could look like this:

onClick="myOnClick()"

and in Javascript:

function myOnClick(e) {
    window.parent.document.getElementById('webcam_show').src="webcam_html5/index.php?text_area='ta_proprietario_altera_foto64'&frame_destino='frame_proprietario_foto_altera'";
    window.parent.div_mostra('webcam');
}
  • 1

    True, thank you very much, much more elegant.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.