open selected wordpress post with javascript

I’d like to create a link that opens the selected post via javascript onclick in the loop.

If I use <a href="<?php the_permalink(); ?>More...</a> in the loop it opens the correct post.

Read More

But If I use

<script>
function open_win()
{
window.open("<?php the_permalink(); ?>")
}
</script>

<a href="#" onclick="open_win()">More...</a>

it just won’t open the correct selected post. How can I make this work?

Related posts

1 comment

  1. You could use the following:

    <script>
    function open_win( thePostURL )
    {
    window.open(thePostURL);
    }
    </script>
    <a href="#" onclick="open_win( '<?php the_permalink(); ?>' )">More...</a>
    

    It seems like a bit more work than it’s worth though, the following would have the same result of the link opening in a new window:

    <a href="<?php the_permalink(); ?>" target="_blank">More...</a>
    

Comments are closed.