In ColdFusion, how to I remove the text at the end of my URL? - facebook

Sometimes, links open pages in my website with weird text at the end of it (like Facebook). I would like to remove that text, since my page will not display with it there.
For example, what I would like to do is tell my page that if the URL has text after a pound sign, remove it and open the URL without it.
So if someone opens my page with:
http://www.example.com/news/stories/this-is-a-news-story/#sthash.MmwTdqVa.dpuf
I want it to correct and open the page
http://www.example.com/news/stories/this-is-a-news-story/
How would I do that? I know how to do this with PHP, but I'm new to ColdFusion.
Thanks!
Brendan

Are you using a service like AddThis.com? If so, these (and other) marketing services may add fragment to URLs for tracking purposes. They're harmless, but here's AddThis instructions on how to remove them if you use their service. (Check w/your marketing team before you do this.)
http://www.addthis.com/academy/removing-hashtags-anchors-and-tracking-codes-from-your-urls/
The fragment is not passed to the ColdFusion server and not in the CGI scope. It's intended to be available and used in the client browser only. This should not be causing any problems with "ColdFusion" generating pages, so your problem may due to javascript. Open up Web Developer tools (F12) to identify any javascript errors that may be caused by the unexpected fragment. (You didn't provide a URL or error message, so it's difficult to troubleshoot the problem you may be encountering.)
Here's an existing solution on StackOverflow that you could you use to remove the fragment client-side:
https://stackoverflow.com/a/13824103/693068
// remove fragment as much as it can go without adding an entry in browser history:
window.location.replace("#");
// slice off the remaining '#' in HTML5:
if (typeof window.history.replaceState == 'function') {
history.replaceState({}, '', window.location.href.slice(0, -1));
}
I would only advise performing this once during pageload and maybe include a filter to preserve any fragments you actually want to preserve.
As a side note, I occasionally add Go to Top to long pages without any matching #top element. Normally any id that is not found will force the browser to automatically scroll to the top.

Related

Is it possible to create a canonical URL for pages with just a pageid in confluence?

I need to groups each space in the Piwik web analytics software. The cleanest way to do it would be if all URL´s had the spacekey in it, to allow each space-owner to easily get a complete view of their space and retain all functionality like browsing the site with an analytics overlay.
Some URL´s are canonical, however some just have an URL like /pages/viewpage.action?pageId=199921170
Is there some way through the AJS API or other method to find force a working URL in the form: /display/spacekey/title-of-page
The most important part is to have the spacekey in the URL. If there´s no workaround I might just generate an invalid URL by inserting spacekey and let each space-owner fix their page-titles if they want working analytics :-)
We are running Confluence version 5.10.7
(There´s an unresolved open issue on https://jira.atlassian.com/browse/CONF-11285 concerning the broader issue of sometimes having ugly URLs in confluence)
Instead of adding an incorrect URL, you could use a custom variable to record the space key, e.g.
_paq.push(['setCustomVariable','1','Space Key', AJS.params.spaceKey]);

urlread pound sign (#) doesn't work

Trying to read in the pricing lists under pricing information tab:
urlread( ' http://www.cefconnect.com/Details/Summary.aspx?Ticker=KYE#pricing ' )
But in url '#pricing' doesn't help.
Any suggestions?
As already pointed out by Darin, it's no use adding #pricing to the URL. The web page uses client-side techniques to switch between tabs; not something that can be used by urlread.
Summary.aspx always returns all tabs together as one big page. CSS and JavaScript make it look like a collection of tabs, when opened in a web browser.
Use the developer toolbar of your web browser to inspect the web page. For example in Google Chrome, just right-click on the section you are interested in, and select 'inspect element'.
I don't know what you are going to do with the result of urlread, but you'll probably have to do some parsing to distill the information you need from the HTML clutter.
Please note Summary.aspx launches additional HTTP requests to retrieve additional data. Use the 'Network' tab of Chrome's developer toolbar to analyze that behavior. For example, the following request is made when you click 'GO' after adjusting the pricing history filter criteria.
http://www.cefconnect.com/Resources/TableData/?Type=PricingHistory&Cusip=48660P104&param0=1M&param1=06/06/2014
At first, this seems to complicate the whole matter, but it may actually be a great opportunity. You can call urlread with the URL above, and get some data in JSON format, which is far less cluttered than HTML. Adjust the parameters to get different data. I'm not sure what 48660P104 is; it might be an internal representation of KYE. You may want to use an initial HTTP request to Summary.aspx to retrieve that code; you'll notice the webpage is littered with URLs containing the same parameter Cusip.
The # character has a special meaning in an url. It represents the fragment identifier and the value following it is never sent to the server. Only client side javascript can access it. You will need to url encode the value if you want to send it to the server:
urlread( ' http://www.cefconnect.com/Details/Summary.aspx?Ticker=KYE%23pricing ' )
This also stands true for other special characters. You need to properly encode them.

Is it possible to add adverts to a custom Facebook Page Tab app?

I need to create a custom Facebook Page Tab app which will show an external site in an iframe. This need to have adverts on it but I'm not sure if this is possible as the site is hosted externally.
I'm not sure if I need to sign up to the Facebook Audience Network to get approved etc. either?
Any help or advice would be great.
Many browsers have this limitation of not allowing external sites to be shown in an iframe. Imagine the case when you are working hard to create a site and others show all your content in iframes. That is, naturally frustrating.
However, there is a candidate-solution: Let's suppose you create a page which sends a request to the other site and appends all the content into the body and head of your page. This is very much possible, so the solution is to:
Create a page in your site, let's call it outsider
In the server-side code of your outsider page send a request to the desired page to be shown
You will get the html of the page. Process it and include its content into the head and body of outsider. This includes:
3.1. Checking all the CSS to be reached, as the target page might refer to local CSS, which is unreachable locally at your end. Process the URLs of CSS files
3.2. Checking all the Javascript to be reached, as the target page might refer to local JS, which is unreachable locally at your end. Process the URLs of JS files
3.3. Apply the idea described in 3.1. and 3.2. for other resources, like images, until you are satisfied with the content of outsider
Create an iframe, having the source to point to outsider. outsider is inside your scope, so it should be shown
NOTE: If the site owning the target page does not like the possibility of you showing their content inside iframes, they might protect it by, let's say, having Javascript in their code, which checks whether the page is inside an iframe. Remove that code while processing the response to your request. If nothing else prevents you from showing the page in an iframe, then you should achieve success.

Preserve Google +1, Facebook Like, and Twitter Tweet This button counts after URI change

My question is very simple: is there any way to (programmatically, technically, or manually) make a Google +1, Facebook Like, or Twitter Tweet This button preserve its count after a change of URI?
Programmatically: Doing something with the javascript to make it show the combined counts of two URIs while posting the new action to only the latter.
Technically: Do they detect and follow a 301 redirect from the original resource? Is there any special text I can include in the HTTP header to tell them that they should move all "points" from the old URI to the new one?
Manually: Some form somewhere on their site that I can submit or someone I can email that will be able to copy our points over to the new URI?
(note that I use URI and not URL in this question on purpose. The canonical resource link is changing from something.php?id=idnumber to /mycoolproduct/)
EDIT
Bounty started, but don't answer with "it can't be done"
I believe there is only one solution that fits your request above universally. That solution would be to 301/302 the old URIs to the new URIs and then keep using the old URIs with your social buttons. All the major social buttons allow you to specify the URL for which to like/g+/tweet/etc. This would preserve your existing social share counts and all shared posts would still direct to the same page. The choice now becomes whether to 301 or 302 redirect. A 302 may help preserve current search placement and avoid loosing your ranking if its pretty good. A 301 redirect (moved permanently) will cause search engines to start indexing your new URLs and dropping the old ones. This might cause a loss in current search rankings. It appears that as of this post, nobody is honoring redirects for social votes of any kind.
So I think the the safest route is to 302 redirect and continue to use the old URIs for social votes. You will keep your equity this way, but must maintain your redirects and become even more invested in the old URI template. How are your redirects implemented? .htaccess? or in page? You will need to weigh the cost-benefits for your case.
Otherwise you should probably 301 and start using the new URIs for your social buttons. In this case you might loose your social equity, but are free to build new without fear of messing up anything. If the social equity you are replacing can be recouped in say 6 months or less I wouldn't bother with it and start fresh.
However, this brings up an interesting point. You mentioned programatically adding two counts. Well yes, you could put together some JavaScript to add a couple counts together, but I gotta ask why? Adding them together for visual display purposes will not actually help increase referral traffic or search ranking. So its just a facade that I don't think helps you. If you're just looking to fool your visitors into thinking you're popular, why not just generate an image server side that keeps counting up. (bad joke, don't do it!) Bottom line you can't actually redirect your social equity, you may be able to pretend to have moved it, but you can't actually.
Considering your original question asks about several social buttons, its important to note that even if one or two of these services started honoring redirects when applying social votes, it wouldn't relieve you from making the decisions above. You'll still need the redirects for existing backlinks, and if you are supporting multiple social buttons on your page the choice of redirect type will need to be made with all of the social buttons in mind.
I can't speak for how to do this with Twitter/G+ but for Facebook:
You can't 'move' the likes and comments between URLs, and for new content you should definitely start using the new URLs, but for your existing URLs you can still have the original like counts/comments work if you:
Continue pointing the Like button on the new URL to the old URL (i.e <fb:like url="http://oldurl"/>
Add an exception to your redirect code so that when Facebook's crawler (facebookexternalhit/1.* - currently 1.1) accesses it, the original set of open graph meta tags are displayed (this will keep the description, title, thumbnail, etc, working as before)
Other users that land on the 'old' URL will still be redirected to the content in its new location
I have a real solution to this problem it might not be the most conventional but it does work 100%. Using a simple jQuery plugin called sharrre. Keep in mind I'm not the best jQuery coder (If you see improvements please let me know!) but this works regardless.
Here is how I did it on my site:
Using the sharrre plugin you can add the current share count to any element on your page. I simply got the data for both URLs then added them together and displayed them on the like, tweet, share, etc buttons.
This example is with Twitter but I'm doing this with Facebook, Google Plus, Pinterest and Linkedin. Here is the code:
<li id="twitter" data-url="CURRENT-URL" class="twitter sharrre"></li>
<li id="twitter-old" data-url="OLD-URL" class="twitter sharrre" style="display: none;"></li>
Then I called sharrre's code:
$(function(){ sharrreItUp(); }
This is how my function looks on my .js file:
function sharrreItUp() {
$('#twitter').sharrre({
share: {
twitter: true
},
enableHover: false,
click: function(api, options){
api.simulateClick();
api.openPopup('twitter');
}
});
$('#twitter-old').sharrre({
share: {
twitter: true
}
});
setTimeout(function(){
var oldTwts = $('#twitter-old .box .count').html();
var newTwts = $('#twitter .box .count').html();
$('#twitter .box .count').html(parseInt(oldTwts) + parseInt(newTwts));
}, 2000);
}
And BAM... you have your new URL being sharrred and the old shares from different social networks get added into them.
Unfortunately, there is no solution for this. We have tried all possible solutions and you will simply lose your social equity if you do a 301 Redirect. We found it to not be worth the hassle of trying to maintain our vote counts, and have instead pointed our buttons to the homepage in the interim of moving to the new url structure.
demo: http://so.devilmaycode.it/preserve-google-1-facebook-like-and-twitter-tweet-this-button-counts-after-ur/
i don't wanna say something wrong, but i think you just need to define the URI inside each share button, so no matter from what URL the vote come from, the defined url will be used as count.
if you, instead already have two different sources and you want to join it, you should follow the iframe src and scrape the count from it; for google +1 the div id that contain the count is #aggregateCount for twitter is #count; an example could be as below:
<?php
$doc = new DOMDocument();
$doc->loadHTMLFile('iframe-url-goes-here');
$count = $doc->getElementById('aggregateCount');
echo $count->nodeValue;
?>
then, on your page after the DOM is loaded and the widget are loaded, you can append your own value.
hope this help, in anycase i prefer the first way.
Put in the head of the new page
<meta property="og:url" content="old_url_here"/>
This way Facebook attributes likes for the old page. The only downside is that this way when people share your link, the old rich snippet will be included.

How can I pull in my BlogSpot page into a page on my web site

I have a blog on BlogSpot.com, and I have a domain based on my own name. I want to have a URL on my site (like http://www.mydomain.com/blog) that will then pull in the content from my blog page, but I want the URL in the address bar to stay on http://www.mydomain.com/blog, so that it does not look like you left my site.
(I have a Windows hosting account on 1and1.com)
I did Google this question, and I found how a few things, like:
1: Adding a tag in to "refresh". Tried this, but it changes the address bar.
<meta http-equiv="refresh" content="0; URL=http://myblog.blogspot.com" />
2: I also learned about the html iframe thing, but it has height and scrollbar issues.
3: Then, I found this partial code snippet, but I don't know what to do with it, or if it will even work against the BlogSpot server, or on my server:
<%
Set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objHTTP.Open "GET", "http://myblog.blogspot.com", false
objHTTP.Send
Response.Write objHTTP.ResponseText
%>
I am a client app guy, so this web stuff is all new to me.
Any help will be greatly appreciated.
The third option will probably work for the initial page load, but any links on the page will then direct the user to the BlogSpot page, and change the url. It simply fetches the page from blogspot, and then sends it to the user without any changes.
For me, the changing url is not a big deal, as long as it's easy for the user to get from one to the other easily; have prominent links on either page that tell the user where they go. Most people don't care about the url, they just care about the content.
Using an IFrame is probably your best bet. Many Facebook applications are in IFrames and still integrate very well.
I think using a regular frame or an iFrame is probably the easiest solution. What kind of scrollbar issues did you encounter? You can set custom values for some of these attributes, just check out the documentation here:
http://www.w3schools.com/TAGS/tag_iframe.asp
If you didn't want to use frames, you could actually proxy the entire page using a server side application like Squid. However, this is more difficult to setup, requires the ability to install software and configure firewall/iptable settings on your host, and must be configured properly to prevent malicious abuse.
-Mark
Here are some options you can try:
If you have PHP installed:
<?php
echo file_get_contents('http://myblog.blogspot.com'); // or you can use fopen()
?>
Or Server-Side-Includes installed:
<!--# include virtual="http://myblog.blogspot.com" -->
You can also pull blog content from Blogspot using the Blogger Data API.
The advantage of this is that you can reformat and reorganize the content to match the style of your website. The disadvantage is that it's more work than an iframe, and you probably won't match the full functionality of Blogspot.
I'm playing with this now to see whether I can use Blogspot as a type of CMS for a club news system.