Custom field in external Javascript

I had a similar problem using custom field values in a widget that used JavaScript. I wrote a tutorial explaining it. Try this code:

<?php 
global $post;
$cf = get_post_meta($post->ID, 'my_custom_field', true);     
?>

<button onclick="window.open(<?php echo json_encode($cf); ?>);">Click me</button>