-1

I went over many posts regarding this issue, yet can't figure out how to escape this syntax.

I'm simply trying to pop up an editing window via PHP echo of a JavaScript window.open and pass that window a prame from MySQL.

The code is echo'ed out along with a table that is dynamically generated via PHP. Inside that echo the last line is the problematic one, that I can't seem to get to function properly.

<a href="#" onClick="window.open( "popup.php?message='.$Url.'", "myWindow", "status = 1, height = 350, width = 1022, resizable = 0 " )" class="bstyle">E</a></td>

Note: I have went over many posts here dealing with this issue, and tried out many solutions, none of which worked out. I'm sure this is very simple to handle, yet I have been steering at this thing it is slipping my attention.

2

4 Answers 4

1

You can embed PHP into your HTML:

<a href="#"
   onClick="window.open(
      'popup.php?message=<?php echo $Url; ?>',
      'myWindow', 
      'status = 1, height = 350, width = 1022, resizable = 0'
   )"
   class="bstyle">
      E
</a>

P.S. The weird indentation is just so that you can read it here on SO. Don't actually use it in your code.

Sign up to request clarification or add additional context in comments.

Comments

0

Use a backslash to escape characters in PHP.

echo '<a href="#" onClick="window.open( \'popup.php?message='.$Url.'\', \'myWindow\', \'status = 1, height = 350, width = 1022, resizable = 0\' );" class="bstyle">E</a></td>';

Comments

0
echo '<a href="#" onClick="window.open(\'popup.php?message='.$Url.'\', \'myWindow\', 
  \'status = 1, height = 350, width = 1022, resizable = 0\')" class="bstyle">E</a></td>';

If you were writing html, and wrote this:

<a href="#" onClick="window.open( "popup.php?message=blah", "myWindow", 
  "status = 1, height = 350, width = 1022, resizable = 0 " )" class="bstyle">E</a></td>

your onclick wouldn't work because it would just hold the value window.open(. You can define the string within the string value of onclick using single quotes. And since in my case I (not sure if you are, but it looks like it) am defining my string to echo using single quotes, I need to escape the ones in my string with the \ character.

Comments

0

You can put a variable inside your HTML code by echo'ing the variable.

<a href="#" onClick="window.open ( 'popup.php?message=<?php echo $Url; ?>', 'myWindow', 'status = 1, height = 350, width = 1022, resizable = 0 ' )" class="bstyle">E</a></td>

I would also like to recommend urlencode in this case. The reason behind this is, because you echo out the $Url variable. Whenever $Url contains HTML characters like for example " or ' then your javascript call will break.

In your popup.php you can then urldecode the message so that it becomes normal again.

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.