we have problem that we are unable to solve and we really need help with it. We have page with a lot of subpages. It works like a blog. Each page has one video and some context. Each page also has Google +1 button. That button should give +1 to current subpage.
We have 75 subpages (so as articles) and most of them works fine with Google +1 button. But about 13 of them are broken right now and count is shared across them and main domain. We don't know when it happens.
We use exactly this code:
<div class="g-plusone" data-size="tall"></div>
<script type="text/javascript">
window.___gcfg = {lang: 'cs'};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
I tried to debug it. So first as you can see, we don't use data-href attribute and also we dont use The page's <link rel="canonical" ... /> tag as it is suggested there: https://developers.google.com/+/web/+1button/#target-url
So first I debuged document.location.href and the value is correct. Then I used data-href attribute to force url. It didn't help. So I inspected iframe generated with google code and even values in iframe are correct. Button should point correct url. Even when you click button, it writes correct title, but somehow it is connected with more pages.
We think that problem could be connected with google crawling. Becouse our mainpage is redirected on last article. But we don't know that for sure.
There are 2 links of pages that shares same count, so they doesn't work correct:
http://www.jaknainternet.cz/page/1750/e-mail/
http://www.jaknainternet.cz/page/1751/socialni-site/
And the article where the button is correct:
http://www.jaknainternet.cz/page/1745/reklama-na-internetu/
EDIT 1:
Some links has correct count right now, but others not. So it seems that problem is really with some google bot that caches our pages...
Actual links that doesn't have correct G+ values (basicaly value>50 isn't correct):
http://www.jaknainternet.cz/page/1759/jak-na-prenos-velkych-souboru/
http://www.jaknainternet.cz/page/1751/socialni-site/
http://www.jaknainternet.cz/page/1739/sdileni-referenci-na-internetu/
Setting the +1 target URL
The URL that is +1'd is determined in the following order:
The button's href attribute
This attribute explicitly defines the +1 target URL.
The page's tag
If the +1 button's href attribute is not provided, Google uses the page's canonical URL. For more information on defining the canonical URL for a page, see this help article.
The URL provided by document.location.href , which is not recommended.
If none of these items are present, Google uses the URL of the page as found in the DOM. Because this URL might contain session IDs, anchors, or other parameters that are not actually part of the canonical URL, we highly recommend either setting the href attribute for the +1 button or adding a tag to your page.
Do I need to use the href attribute?
The href attribute is not required. See +1 target URL for more information https://developers.google.com/+/web/+1button/?hl=pt-br#target-url
Do all my pages need to have a rel="canonical" tag?
No, though we recommend it. If the href attribute isn't set, Google will next look for the rel="canonical" tag on the page. If that isn't found, Google will use the document.location.href. This final value can sometimes be misleading because of state variables often kept in the URL. So, using a rel="canonical" tag can help you specify the exact URL you want +1'd.
Related
I want to change all external links on my blog (blogspot here, that's why I'm looking for jQuery code) without changing the posting of my blog because I need a lot of work if I do that.
For example, my website is example.com.
I want to change all external links to
http://example.com/p/go.html?url=http://externallink.com
without need for any changes on my blog post. I don't have any idea to start with.
SOLVED: https://gist.github.com/2342509 Thanks everyone :D I just need to change it a bit.
In jQuery you can try:
// DOM ready
$(function(){
$('a[target="_blank"]').prop('href', 'http://example.com/p/go.html?url=http://externallink.com');
});
Ofcourse this will only work if you have set the target="_blank" property/attribute in HTML and if you want all links to open the same url. This idea derives from the fact you want to have external links open automatically in a different tab/window.
If this is not the required functionality, you can use a custom data- attribute in a similar way. Only difference is you will need to loop each link, and get the data from it.
// DOM ready
$(function(){
$('a[data-href]').each(function(){
var anc = $(this),
href = anc.prop('href'),
dataHref = anc.data('href');
anc.prop('href', href + '?url=' + dataHref);
});
});
HTML example:
external link
And now you will probably need to add more information if that is still not what you want.
Going off of #Tim Vermaelan's answer, you could try this, which will check for every link that doesn't start with your website's URL without relying on it being target="_blank":
$('a:not([href^="http://yoursite.com"])').prop('href', 'http://example.com/p/go.html?url=http://externallink.com');
I'm having this issue with joomla 2.5 and the Meta robots tag.
Basically joomla has this black hole in it that doesn't matter what the URL is as long as you have a article id that is valid it will generate a page.
example:
http://www.clet.edu.au/dasfjahsd/sajfhas/61-afssfas
61 is a valid id so it will display a page however it is a wrong rendering of the page.
this will be the correct rendering for that article
http://www.clet.edu.au/online-study/whs-courses/diploma-of-work-health-and-safety
What i've came up with is, our website doesn't have any urls with numbers on it, so pretty much any url that has a number on it it's wrong... so i've done this code:
$(document).ready(function(){
var pathname = $(location).attr('href');
var NO_NUMB = new RegExp("[0-9]");
if (NO_NUMB.test(pathname)) {
$('meta[name=robots]').attr("content", "noindex, nofollow");
}
});
What it does, it checks for numbers on the url and changes the meta robots to noindex nofollow. That works in part, it changes the meta robots but only does it on the browser DOM and not straight on the source file.
So when you go on your browser and click inspect element you can se the noindex nofollow tag but when you click view source, you will see index follow...
According to google support, google looks at the page source not the DOM on the browser... so it will never see the noindex nofollow tag...
I'm wondering is there a way to do that on PHP so it changes the meta keyword on the source code not on the browser DOM?
cheers,
dan
Try this ,
Instead of changing the meta data from Javascript try it from php.
Joomla have a document class for this purpose.
$document = JFactory::getDocument();
$document->setMetaData('keywords', "keyword1,keyword2, etc.");
$document->setMetaData('robots', "index,follow");
$document->setMetaData('author', "Jobin Jose");
$document->setMetaData('title', "Your meta title");
$document->setDescription( "Your meta description" );
$document->setTitle("This is my page title");
For more details read article How to set meta info of Joomla page
Hope its helps..
When I enter a link (video, image, URL, etc.) in Facebook's "What's on your mind?" form, it auto-detects the link and converts it to a thumbnail with a brief description below the text-area. Can anyone provide me with insight or a link to get me going on how to achieve this?
There's a javascript attached to the textarea change event. The javascript detects if the content of the textarea is a url, if it is, the javascript call a webservice that visit the url looking for the page title, the page description, etc, (or the open graph protocol meta tags), if it find each one of the tags they are returned to the javascript who proper organize then.
Facebook also cache this content, and if the same url is posted by another user, he uses the cache values instead of revisiting the page.
The open graph protocol meta tags:
http://developers.facebook.com/docs/opengraphprotocol/
using something like
var input = document.getElementById("textarea");
input.addEventListener("change", checkLink(e));
input.addEventListener("blur", checkLink(e));
function checkText(text){
var exp = "((ht|f)tp(s?))(:((\/\/)(?!\/)))(((w){3}\.)?)([a-zA-Z0-9\-_]+(\.(com|edu|gov|int|mil|net|org|biz|info|name|pro|museum|co\.uk)))(\/(?!\/))(([a-zA-Z0-9\-_\/]*)?)([a-zA-Z0-9])+\.((jpg|jpeg|gif|png)(?!(\w|\W)))";
return text.match(exp);
}
function checkLink(e){
//here you would want to use a regular expression and check for http:
var regularExpression = !!checkText(e.target.innerHTML); // returns true or false
if(regularExpression){
e.target.innerHTML += "<a href='#'><img src="" alt="" /></a>";
}
}
good resource for regular expressions - http://regexlib.com/Search.aspx?k=image&c=-1&m=-1&ps=20
Warning -- have to leave for work so regular expressions are not checked.
Take the link value and run it through a regular expression that looks for ^http:...[^\s] or ^https:...[^\s] and returns those.
Then, pass those URLs to your server and have your server retrieve the document and return a snippit for you to then put in your document. You must have your own server to help because Javascript, by itself, has security restrictions. Google same origin policy for more info.
There might be a duplicate of this (I've tried checking questions on creating dynamic links but they reference a static link - I want this link to be hidden from the user). On testing the following code on the ww3 site:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
document.write("<a href="www.google.com">Google</a>");
</script>
</body>
</html>
I get:
http://www.w3schools.com/jsref/%22www.google.com%22
As the link address rather than www.google.com.
How do I correct this problem? And how do I make it so the link only appears after a set time? Note, this is a simplified version of the code for readability (the dynamic link will including two floating point variables assigned at the time the script is run).
An <a> tag's href must include the protocol http://, otherwise it links to a document relative to the page the link is on:
// Print quote literals, not html entities `"`
document.write("<a href='http://www.google.com'>Google</a>");
The use cases for document.write() are often limited since it can't be used after the page has loaded without overwriting the whole thing. A lot of the time you will want to create the element after the page has already rendered. In that case, you would use document.createElement() and appendChild().
// Create the node...
var newlink = document.createElement('a');
newlink.href = 'http://www.google.com';
// Set the link's text:
newlink.innerText = "Google";
// And add it to the appropriate place in the DOM
// This just sticks it onto the <body>
// You might, for example, instead select a specific <span> or <div>
// by its id with document.getElementById()
document.body.appendChild(newlink);
By the way, w3schools is not affiliated with the W3C, and their examples are generally not recommended since they are often out of date or incomplete.
You have 2 issues:
1) You need http:// before the URL so it's: http://www.google.com
2) You don't need to use quotes in document.write, but if you want to you can do one of these 3:
document.write('Google');
document.write("<a href='http://www.google.com'>Google</a>");
document.write("<a href=http://www.google.com>Google</a>");
Use the slash "\" to escape the quote
To make the link absolute, include the "http://" at the start of the url. Write out:
<a href="http://www.google.com">
instead of
<a href="www.google.com">
The second example will be treated as a relative url, like index.html for example.
I'm looking over some previous developers code and I come across this line:
location.href = '#' + variable;
Which has the effect of updating location.hash. Remove the '#' and of course it redirects to the non-existent url. Playing around a bit it seems I can set the hash via location.href as long as the value starts with '#'. This line or similar is used a lot, but I can't seem to find any documentation the supports this behavior of it updating location.hash by setting location.href this way.
I would like to see something showing this isn't just a happy accident that this works so I don't have to re-code all the situations where this is used. Anything you can link me to would help.
Would it be better to just changes these to properly set the location.hash anyway?
Thnks
At a guess this is because setting location.href to value is supposed to have the same behaviour as clicking a link whose href=value would; it's not supposed to replace the contents of the address bar, because then you'd have to build absolute URLs everytime you wanted to use location.href.
Assigning values to location and location.href was apparently there back in Javascript 1.0, so it's entirely possible this wasn't properly specified anywhere – neither the Mozilla or Microsoft documentation go into detail. HTML5 specifies the behaviour, most likely retroactively.
This is a good place to start your journey on the location properties.
https://developer.mozilla.org/en/window.location
By the way, #something is a valid url and assigning a new url to window.location cause the browser to navigate to the new destination.
#something is called hash and direct the browser to an anchor on the current document, or to the top of the document if the anchor does not exists.
http://docstore.mik.ua/orelly/webprog/DHTML_javascript/0596004672_jvdhtmlckbk-chp-10-sect-2.html
So what happens is when you set location.href to something that is not seen as an absolute path. The browser will automatically put the current url prepended to whatever value you are trying to set it to.
So "#section1" = "www.mysitethatistoocoolforschool.com#section1"
and "section1" = "www.mysitethatistoocoolforschool.comsection1" (this does not exist)
This URLs with a '#' char are called anchor based URLs, they're not supposed to redirect the user from the page, instead they just update the position of the page by some offset, the same way as setting the location.hash you cited.
As stated by Sii this works because when you change the location.href value it's like you're clicking on a link for example then you have the following equivalence:
<a href="#toc" >Go to Table of Contents</a>
Is the same as:
location.href = "#toc";
Both of them would result in your location.hash variable to have the value toc.