I have a function that opens up a browser window:
function startmonitor(camerahash, cameraname, cameraflashquality, cameramotion)
{
window.open("mydir/file.php?user="+'<?php echo $id_hash; ?>'+"&camera="+camerahash+"&name="+cameraname+"&quality="+cameraflashquality+"&motion="+cameramotion, "Webcam_monitor");
}
cameraname is passed in from a button in html:
<button id="monitor" onclick="startmonitor('<?php echo $result_cameras[$i]["camera_hash"]; ?>', '<?php echo $result_cameras[$i]["camera_name"]; ?>', '<?php echo $camera_quality_flash; ?>', '<?php echo $camera_motion; ?>');">Start Camera</button>
cameraname does take special characters. Such as Al's camera. Because of the special character it messes up the window.open line. Anyone have ideas how I can rewrite the window.open line to accommodate this?
You might try encodeUri
Edit:
Actually, because you are wanting to encode the apostrophe, you would need to use the escape function around the variables you wish to escape. In this case it would be used around the
cameranamevariable.Edit 2
OK, it looks like, based on your comment below, that you need to escape
cameranamebefore it enters yourstartmonitorfunction. So you would actually escape it in your button code and not in your function code.Edit 3
Wow – I’m retarded. Just encode with php’s urlencode function before outputting to the page.