Facebook Share Button on Main Page in Wordpress - facebook

I have this as my facebook share button on my "single.php" template in Wordpress:
<script>
function fbs_click() {
u=location.href;
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;
}
</script>
<style> html .fb_share_link { padding:0px;background:url(http://www.mydomain.com/images/compartir-fb.png) no-repeat top left; }</style>
I tried adding the same code to my "index.php" but it doesn't seem to work, when i click on the button, it instead shares my main website "www.mydomain.com" but I want it to share each individual article. So itried replacing:
"u=location.href;" to "u=<?php the_permalink() ?>"
but all it does it opens a new tab with www.mydomain.com
I am really trying to figure out where to place <?php the_permalink() ?>?

So itried replacing:
"u=location.href;" to "u=<?php the_permalink() ?>"
That should only give an error in your browser’s JavaScript console, since it is not valid JS syntax, because you neglected to put a text literal in string delimiters.

try to convert it as below ...
wp_reset_query();
if(is_home()){
$url = site_url();
}else{
$url = get_permalink();
}
<script>
function fbs_click() {
u='<?php echo $url;?>';
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;
}
</script>

Related

For some reason this PHP doesn't take place after submitting a form

I have the following HTML +javascript form:
<script>
window.addEventListener("load", function() {
var form = document.getElementById("myform");
var link = document.getElementById("submit-link");
link.addEventListener("click", function(event) {
event.preventDefault();
form.submit();
}, false);
}, false);
</script>
<form action="" method="post" id="myform">
<a id="submit-link" href="http://www.google.com">Submit</a>
</form>
The following CSS code for design:
.ssd {
border: none;
background-color: transparent;
padding: 0;
cursor: pointer;
font-size:89%;
display:inline;
text-decoration: underline;
color: #00c;
}
And this PHP code:
if(isset($_POST['myform'])){
$xmla = new SimpleXMLElement('passwords/' . views . '.xml', 0, true);
$plus = $xmla->goodx;
$result = $plus + 1;
$xmla->goodx = $result;
$xmla->asXML('passwords/' . views . '.xml');
}
Now, Every time that the user clicks on the value "Click", the XML file is supposed to be updated with data, and then redirect to google.com. It works, but when the user places his mouse over the link, he sees the URL of my site, and not google's. any ideas how to solve it?
Use action="" and redirect to the right google.com page.
Look at the google.com URL to know how it works.
Edit:
To see the link in each browser, you will need to use a link and post the form with JavaScript:
<script>
window.addEventListener("load", function() {
var form = document.getElementById("myform");
var link = document.getElementById("submit-link");
link.addEventListener("click", function(event) {
event.preventDefault();
form.submit();
}, false);
}, false);
</script>
<form action="" method="post" id="myform">
<a id="submit-link" href="http://www.google.com">Submit</a>
</form>
This way, the user will see the google link and it will post to your PHP script.

Facebook Requests Dialog appears behind DIV (in Safari)

I have several DIVs with z-indexes (like: z-index: 999991;). In Safari, this results that the Requests Dialog I have created appears behind some DIV's.
Is their a way to give the Requests Dialog a z-index or something so it will always appear on top of every DIV?
My Requests Dialog code:
<script src="http://connect.facebook.net/en_US/all.js"></script>
<p>
<input type="button"
onclick="sendRequestViaMultiFriendSelector(); return false;"
value="Send Request to Many Users with MFS"
/>
</p>
<script>
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'Join me on Mahjong Solitaire!',
exclude_ids: '<?php echo $friends_array; ?>'
}, requestCallback);
}
function requestCallback(response) {
// Handle callback here
}
</script>
Hope this is possible!
Made the z-index smaller and this indeed worked!

JQTouch/PHP problem - function isn't firing

I'm very new to web development so forgive me for any obvious questions. I'm having trouble getting this function to work. I've been racking my brain for a while now.
I placed the php code in the url window and it displays the appropriate output so I know the php code is ok. I just can't get this function to display the query results into the "wine_categories" . Thanks in advance for all your help. Here's the code:
<script type="text/javascript">
var jQT = new $.jQTouch();
function showtype(type)
{
$('wine_categories').children().remove();
$.ajax({
type:"POST",
url:"get_winebot_type.php",
success:function(html){
$('#wine_categories').append(html);
jQT.goTo('#wine_list', 'slide');
}
});
return false;
}
</script>
Here's the <div>:
<div id="wine_list">
<div class="toolbar">
<h1>Categories</h1>
<a class="button back" href="#">Back</a>
</div>
<div id="wine_categories">
</div>
The most obvious mistake I can see is this line:
$('wine_categories').children().remove();
You missed a hash in front of the ID:
$('#wine_categories').children().remove();

How could I create a popup form when clicking a button?

I would like to create a popup form which will ask a user if he/she agrees with the terms and condition and has a post and cancel button. How could I create one? Could you give me an example. Thank you.
<html>
<head>
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("Leave tizag.com?")
if (answer){
alert("Bye bye!")
window.location = "http://www.google.com/";
}
else{
alert("Thanks for sticking around!")
}
}
//-->
</script>
</head>
<body>
<form>
<input type="button" onclick="confirmation()" value="Leave Tizag.com">
</form>
</body>
</html>
Taken from TizTag...or you could use jQuery Dialog :)

Basic FBJS in an FBML Facebook application

I have tried just about every suggestion known to man to get the basic FBJS working in my FBML app.
Here is my code
<script>
<!--
function areyousure(description,id,opt) {
debugger;
var dialog = new Dialog(Dialog.DIALOG_POP).showChoice('Are you sure?','Are you sure you want to delete "' + description + '"? This action cannot be undone!','Yes','No');
dialog.onconfirm = function() {
document.setLocation("http://apps.facebook.com/myapp/delete.php?rec
ord=" + id + opt);
}
}
//-->
</script>
<a href="#" onclick="areyousure(arg1,arg2,arg3);" >click me</a>
When I click the link, I get a a1234543_areyousure not found.
Help Please.
Thanks
I think you are messing a ";" in a href :
<a href="#" onclick="areyousure(arg1,arg2,arg3);" >click me</a>
The parameters didn't exist. This works:
<script>
<!--
function areyousure() {
var dialog = new Dialog(Dialog.DIALOG_POP)
dialog.showMessage('test','foo');
}
//-->
</script>
<a href="#" onclick="areyousure();" >click me</a>