Dynamic facebook like button on localhost - javascript

When I use PHP to parse current URL into data-href attribute , the widget breaks and does not render.
Console says its because of empty string parsed into getElementById on the fb script.
Documentation says if i omit the data-href altogether , it defaults to current URL.
When I do that it still doesn't render , only when i predefine some static URL.
I am putting this widget into a "footer.php" that gets included after content on every page.
Is this not working for me on my dev server , because the URL is actually localhost ?

I have a similar problem (with a FB share button, though).
The only answer I can give is: Facebook does not seem to accept localhost in the data-href attribute. For me it works with anything else - e.g. with 127.0.0.1 :) .
Smells like you need to use a work-around :-/.

Related

Angular JS application page refresh issue

I am working on an angular application and i have used "$locationProvider.html5Mode(true)" in my route config to avoid /#/ in URL. I have also added base href="/" in index.html and everything is working fine on refresh of pages.
But when i am trying to refresh the page having URL
"http://localhost:3000/home/:JavaScipt%20SC2.0"
Then i am getting Cannot GET /home/:JavaScipt%20SC2.0 error.
I think error is due to name "JavaScript SC2.0" containing .(dot) symbol. Any clue to fix this issue?
But when i am trying to refresh the page having URL
"http://localhost:3000/home/:JavaScipt%20SC2.0"
Your route has at least two problems:
First, document name misspelled, shouldn´t it be JavaScript? (with R)
Second, you can´t use home/ : Jav... (/:Javascipt??)
try again with http://localhost:3000/home/JavaScript SC2.0 into a variable and pass it.
More info in this link
PS: If (whoever) knows so much that can mark my answer as not valid, please ALSO post a valid answer, not just a negative ;)
you can try on send it on another state:
or you can use the $window dependency into your controller, and use as javascript.

Changing pages URLs without using route controllers

First of all, sorry for the lame question (probably). I tried to search for an answer but I'm not finding everything I need for my issue.
So... I have a bootstrap website and I am trying to change the page URLS to appear like this :
For example : www.site.com/AboutUs.html - to appear as www.site.com/about-us
I am using the pushState method for this as it follows:
var stateObj = { AboutUs: "about-us" };
history.pushState(stateObj, "About Us", "about-us");
So I get the needed URL address there (www.site.com/about-us).. so far so good. But on page refresh it throws an error stating "The requested URL /about-us was not found on this server."
If I hit the back browser button it goes to www.site.com/AboutUs.html again.(and it is supposed to go on the home page)
My question is :
What am I missing, am I supposed to make a controller and how ?
I am not using C#, I can probably use some help with PHP because I am not good at it. JavaScript / jQuery are welcomed.
Thanks in advance and sorry for the dumb question.
Happy days!
The point of pushState is to be able to say: I have modified the page with JavaScript, the new state is what you would get if you just asked the server for this URL.
You shouldn't use JavaScript for this problem at all. You just want to have a page appear at a particular URL.
You need to configure the server to serve up the content you want on the URL you want.
What am I missing, am I supposed to make a controller and how ?
You need something on the server to handle the URL /about-us.
"A controller" is something you would probably use if you were using the MVC architecture on the server … and it doesn't sound like you are.
More likely you will be wanting to use an Alias, a tool like mod_write, or simply moving the static file to a directory called about-us and renaming it index.html.

How to get browser's current page URL from iframe?

Ok. This might have been asked several times but my problem is slightly different. I have following page tab in my facebook application:
Facebook Page Tab
This facebook page tab has my website embedded as iframe into it. What I want is that is to get the URL of current page inside my application.
For example, if you open above link you see facebook URL in your browser(obviously) address bar. In my iframe I just want to retrieve the URL of the parent page in which it is embedded.
I know same-origin policies in Javascript don't allow playing with cross-domain parent page's markup using javascript but I just want to retrieve the parent page URL, thats it.
Is that possible in ANY way?
Any way to access the address bar URL in my PHP application?
Thanks.
You probably don’t need the “actual URL”, but only the page id, I assume …? That you can get by decoding the signed_request parameter that gets POSTed to your app on initial load into the iframe.
How to “decode” it is described here, https://developers.facebook.com/docs/facebook-login/using-login-with-games#parsingsr
If you’re using the PHP SDK, that has a method already that does this for you.
You can use this to access it in JavaScript:
top.location.href
"top" is better than "parent". Because if your iframe is itself in another iframe then parent will return that iframe's location. "top" will return the highest location.
This will be a tough one, because CORS forbids to access the outside frame:
The referrer doesn't help very much either.
If you want to use the signed_request, and want to send custom data/parameters to your app, have a look at https://developers.facebook.com/docs/appsonfacebook/pagetabs#integrating
You can then fill the app_data parameter, and decode that in your app.
Try one of these:
parent.document.location
parent.window.document.location
parent.window.location
parent.document.location.href
I'm not sure if this will work on facebook though

Javascript Redirects with Pound not working in Wordpress

I have a link to my site on a very popular but now dead website. The link is incorrect, so I'd like to redirect users to the correct page when they visit. I'm using Wordpress for my content.
The problems lie in the fact that the incorrect URL that the website lists is http://www.senntenial.com/#!mysterium/cj6d . From my research, I cannot do a 301 redirect in my htaccess, since this URL has a # sign, and is client only.
So, I tried creating the following script in my header.php file.
if (window.location == 'http://www.senntenial.com/#!mysterium/cj6d'){
window.location = 'http://www.senntenial.com/mysterium/';
}
I would think this would have worked, but it doesn't. To identify the problem, I tried simply inputting window.location = 'http://www.senntenial.com/mysterium/'; Which worked correctly, meaning my problem lies in identifying the current window location.
How can I accomplish this? I assume Wordpress has a funky way of going about things with URL's to make them easier to read that may be messing with my code.
(PS, I tried WP extensions like EPS 301 redirect to no avail.)
Also, the mysterium page is static HTML, and not involved with Wordpress' CMS.
There's window.location.hash which gives the fragment part of the current URI. So something like
if(window.location.hash=="#!mysterium/cj6d"){
window.location = 'http://www.senntenial.com/mysterium/';
}
Might work. You could also use window.location.href which contains the full URI but then you need to check with and without www.

Concatenating pathname with a virtual URL for Tracking PageView

I'm using the Contact Form 7 plugin for Wordpress.
It allows you to put in a single line of javascript in the additional settings to trigger some javascript code when the send button is pressed.
My original code looked like this, which works fine:
on_sent_ok: "_gaq.push(['_trackPageview', '/CallbackFormFilled']);"
The "On_sent_ok:" is a specific parameter for the contact form.
I have a requirement where i need to concatenate the pathname of the URL together with the virtual URL i have created in the code above.
I tested concatenation of strings using 'Alert' to make sure i was doing it correctly, but when using the following code my pageview tracking fails
What is the correct syntax for concatenating the strings correctly here?
on_sent_ok: "_gaq.push(['_trackPageview',window.location.pathname+'CallbackFormFilled']);"
Try:
"_gaq.push(['_trackPageview',"/"+window.location.pathname+'CallbackFormFilled']);"

Categories

Resources