Auto-generated facebook comments boxes - html

I´m implementing facebook comments boxes on my news pages. And it works. The problem is that if I make a comment on one page, it will display on ALL pages which contains fb comment boxes.
Currently my code looks like this:
<b><div class="fb-comments" data-href="http://selandia-ceu.dk/selandia/nyheder.aspx" data-num-posts="3" data-width="500"></div>
<script>
var fb-comments = document.getElementById('fb-comments');
mydiv.innerHTML =
'<div class="fb-comments" data-href="' + document.location.href + '" data-num-posts="3" data-width="500"></fb:comments>';
FB.XFBML.parse(fb-comments);
</script></b>
The website is using Microsoft Server. The url in the code is supposed to refer to the current page one is viewing. Anyone know what I´m supposed to do? :)
The comments are temporary disabled on the pages.
I got the extra bit of code (FB.XFBML.parse) from this thread:
Different Facebook comment box after each ajax call

You may need to clean up your Open Graph tags, as the URL that each comments plugin is pointed to will be scraped by the Open Graph linter and used to determine the canonical URL. The problem is likely that your comments plugins all end up pointing to the same canonical URL:
https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fselandia-ceu.dk%2Fselandia%2Fnyheder.aspx
Use this Debug tool to inspect your Open Graph tags and ensure each page has it's own canonical URL. You also need to correct the fb:admins tag that you have in your HTML as suggested by the debugger.

Related

Facebook plugin on Squarespace blog

I added the Facebook plug-in in the post-code injection block, but then every new blog post includes the same “test” comment of mine. Any idea how to correct so that each new blog has a cleared FB comment section??
The code, as provided to you by Facebook, does not produce a dynamically changing URL for each new blog post. So, we must set the data-href attribute dynamically. The simplest way to do this is to use the following instead of what you're using now:
<div class="fb-comments" data-href="" data-width="" data-numposts="5"></div>
<script>
document.getElementsByClassName("fb-comments")[0].setAttribute("data-href", window.location.hostname + window.location.pathname);
</script>
In the code above, we leave the data-href attribute empty, and then fill it in using JavaScript immediately following the div. The script then inserts the URL of the current page, making the comments unique to that page.

PdfBook Extension - MediaWiki - Fullurl parser function link automatically to every category page

I am able to display a download link in category to download all the pages of that category.
In the below link, it is written as
In order to include this parser function link automatically to every category page, add it to the Mediawiki:Categoryarticlecount page.
Rather than adding the download link manually to all categories, i tried the above. That is, added the download link in Mediawiki:Categoryarticlecount page to automatically include the fullurl parser function link to every category page. But it didnt work.
Parser function link : [{{fullurl:{{FULLPAGENAME}}|action=pdfbook}} | Download]
How to achieve this?
Any help is appreciated.
You have two typos in there:
The system message is at MediaWiki:Category-article-count (note the camel-case in MediaWiki)
The external link syntax is [url text], not [url | text], so it should be [{{fullurl:{{FULLPAGENAME}}|action=pdfbook}} Download]
Other than that, your code looks fine.

retrieving URLs from functions within HTML (python)

I need to scrape some URLs from some retailer product pages, but the specific URLs I need to get aren't in the html part of the page. The html looks like this for each of the items on which one would click to get to the page with the URL I need to grab:
<div id="name" class="hand bold" onclick="AVON.productcontrol.Go(45714);">ADVANCE TECHNIQUES Color Protection Conditioner Bonus Size</div>
I wrote the following to get URLs from the page, but since the actual URLs I need don’t seem to be stored in the page, it doesn’t get what I need:
def getUrls(URL):
"""input: product page url
output: list of urls to products
"""
connection = urllib.urlopen(URL)
dom = lxml.html.fromstring(connection.read())
selAnchor = CSSSelector('a')
foundElements = selAnchor(dom)
urlList = [e.get('href') for e in foundElements]
return urlList
Is there a way to get the link that the function after ‘onclick’ (I guess AVON.productcontrol.Go(#);) takes you to? I don’t fully understand html, and while I’ve read a bit about onclick, I can’t figure out how the function after 'onclick' works.
In order to find the URL that you are taken to on click, you need to find the JavaScript source code of the 'Go' function and read and understand it. It's buried somewhere within a tag or some JavaScript .js file that is referenced directly or indirectly by the HTML page. Happy digging!
Or: you automate the interaction with the web page with a tool like Selenium (http://docs.seleniumhq.org/) and just check where it takes you if you click.

HTML injection into someone else's website?

I've got a product that embeds into websites similarly to Paypal (customers add my button to their website, users click on this button and once the service is complete I redirect them back to the original website).
I'd like to demo my technology to customers without actually modifying their live website. To that end, is it possible to configure http://stackoverflow.myserver.com/ so it mirrors http://www.stackoverflow.com/ while seamlessly injecting my button?
Meaning, I want to demo the experience of using my button on the live website without actually re-hosting the customer's database on my server.
I know there are security concerns here, so feel free to mention them so long as we meet the requirements. I do not need to demo this for website that uses HTTPS.
More specifically, I would like to demonstrate the idea of financial bounties on Stackoverflow questions by injecting a Paypal button into the page. How would I demo this off http://stackoverflow.myserver.com/ without modifying https://stackoverflow.com/?
REQUEST TO REOPEN: I have reworded the question to be more specific per your request. If you still believe it is too broad, please help me understand your reasoning by posting a comment below.
UPDATE: I posted a follow-up challenge at How to rewrite URLs referenced by Javascript code?
UPDATE2: I discarded the idea of bookmarklets and Greasemonkey because they require customer-side installation/modification. We need to make the process as seamless as possible, otherwise many of get turned off by the process and won't let us pitch.
I would suggest to create a proxy using a HTTP handler.
In the ProcessRequest you can do a HttpWebRequest to get the content on the other side, alter it and return the adjusted html to the browser. You can rewrite the urls inside to allow the loading of images, etc from the original source.
public void ProcessRequest(HttpContext context)
{
// get the content using HttpWebRequest
string html = ...
// alter it
// write back the adjusted html
context.Response.Write(html);
}
If you're demoing on the client-side and looking to just hack it in quickly, you could pull it off with some jQuery. I slapped the button after the SO logo just for a demo. You could type this into your console:
$('head').append('<script src="https://www.paypalobjects.com/js/external/dg.js" type="text/javascript"></script>')
$('#hlogo').append('<form action="https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay" target="PPDGFrame" class="standard"><label for="buy">Buy Now:</label><input type="image" id="submitBtn" value="Pay with PayPal" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif"><input id="type" type="hidden" name="expType" value="light"><input id="paykey" type="hidden" name="paykey" value="insert_pay_key">')
var embeddedPPFlow = new PAYPAL.apps.DGFlow({trigger: 'submitBtn'});
Now, I'm not sure if I did something wrong or not because I got this error on the last part:
Expected 'none' or URL but found 'alpha('. Error in parsing value for 'filter'. Declaration dropped.
But at any rate if you are demoing you could just do this, maybe as a plan B. (You could also write a userscript for this so you don't have to open the console, I guess?)
After playing with this for a very long time I ended up doing the following:
Rewrite the HTML and JS files on the fly. All other resources are hosted by the original website.
For HTML files, inject a <base> tag, pointing to the website being redirected. This will cause the browser to automatically redirect relative links (in the HTML file, CSS files, and even Flash!) to the original website.
For the JS files, apply a regular expression to patch specific sections of code that point to the wrote URL. I load up the redirected page in a browser, look for broken links, and figure out which section of JS needs to be patched to correct the problem.
This sounds a lot harder than it actually is. On average, patching each page takes less than 5 minutes of work.
The big discovery was the <base> tag! It corrected the vast majority of links on my behalf.

How to determine what content is active on a page

I am at a bit of loss of knowledge and honestly don't know what to search for. What I need to be able to do is determine what content to show on a webpage that way when I refresh it will not reset everything. For example, if someone clicks on the messages tab I want the browser to know when it refreshes, that is the tab to stay on. I believe this is done through url encoding but I am not sure. Any help would be AWESOME! Thanks fellow coders.
MORE INFO: I have 2 buttons on a page. One is named "home" and when I click it I want the content of the home page to appear in a box named "info-main". I am doing this with ajax requests. When I click on "edit profile", I want the content in div id "info-main" to be replaced with the edit profile information that is retrieved via ajax as well. I need to figure out how if someone refreshes the page... I want it to stay showing the edit profile information rather then going back to the default of "home" content.
MORE INFO(AGAIN)
I just had a great idea. When the page refreshes, I want it to load specific ajax code based on what the url encode is.
For example.... if the url is:
http://www.exampleurl.com/index.php?info=status-load
I want the browser to execute the ajax I have for retrieving status's.
OR
If the url is:
http://www.exampleurl.com/index.php?info=edit-prof
I want it to load the ajax code I have for retrieving profile edit info.
I really hope this helps. :/
The way I do it is I place a # before the link i.e. href="#messages"
Then I link a .js with this code.
$(function () {
var hash = location.hash
, hashPieces = hash.split('?')
, activeTab = $('[href=' + hashPieces[0] + ']');
activeTab && activeTab.tab('show');
});
I hope this helps
For referring an element on your page, you use a link with a hashtag.
For example, if you have a layout like this:
<div class="top-nav">
Home
Edit Profile
</div>
And you have a password edit form on your editProfile page, you can like to it like this:
Edit Profile
if you have a <form id="passwordChange"> on your editProfile.
Read more: http://css-tricks.com/hash-tag-links-padding/