Jump to content

Recommended Posts

can any guru give me an idea what I have done wrong here? Why my onclick function is not working and no popup window is displayed?

 

This :

<a onclick="window.open('http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&&p[images][0]=<?php echo $image;?>', 'sharer', 'toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)">

 

and this also not working

<a href="#"  onclick="window.open('http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&&p[images][0]=<?php echo $image;?>','windname','width=325,height=54,top=50,left=50'); return false;">

 

please advise.thanks

Link to comment
https://forums.phpfreaks.com/topic/270000-php-onclick/
Share on other sites

You may have to urlencode the strings you echo, but since you haven't posted an example of the result it's hard to say for sure. In any case, using rawurlencode () is highly recommended to avoid any problems. You'll also need to use htmlspecialchars () afterwards, with the quotes flag, to ensure that you're not breaking any HTML code.

You also need to manually URL-encode the square brackets in the static parts of the URL, as they're not valid in URLs. Plus manual HTML-encoding of the ampersands, to avoid having them perceived as invalid ISO entities.

 

I recommend the use of the last example to build on, as it's the most valid way of doing it. You could, however, move the JS code into a function of its own for a major improvement of readability (and thus maintainability). Just have the function return false, and then you can call it (approximately) like this:

<a href="http://facebook.com/sharer.php?..." onclick="return popup (this.url, 'windname')">

 

Personally I prefer setting the href to the URL you want to use in the pop-up, as it'll allow the link to work even for people without JS (activated). Plus those of us who like to use other features to open links, features that does not trigger the onclick event. ;)

Edited by Christian F.
Link to comment
https://forums.phpfreaks.com/topic/270000-php-onclick/#findComment-1388306
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.