Alicia Posted October 28, 2012 Share Posted October 28, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/270000-php-onclick/ Share on other sites More sharing options...
Christian F. Posted October 29, 2012 Share Posted October 29, 2012 (edited) 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 October 29, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/270000-php-onclick/#findComment-1388306 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.