plusone.js sometimes is "pending" on chrome? - google-plus

Using Chrome (22.0....), sometimes, when I try to take :
<script src="http://apis.google.com/js/plusone.js" type="text/javascript"></script>
it fails. I mean, if I check the Network console, it says "Pending...", and my .load() events are stuck.
Why? And how can I fix it?
Also tried with :
<script type="text/javascript">
(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>
but it is the same...

I don't see the HTML container for the +1 button defined anywhere in the source of the page that you linked. I see the first script that you referenced on the page, but your page appears to be missing:
<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone" data-annotation="inline" data-width="300"></div>
The second snippet of script is intended for asynchronous loading (preferred) that you reference also would require you to insert the same type HTML container.
You can generate the code to include in your page using the +1 button configuration tool.
[UPDATE]
The g-plusone element apparently is being injected dynamically by jQuery, which has a different onload timing than the +1 button's own onload handler, which explains why sometimes it might display. In this case, you need to use the parseTags: explicit option:
<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
{parsetags: 'explicit'}
</script>
And then after your own JavaScript injects the g-plusone div, you must call:
gapi.plusone.go();
Which will explicitly render all +1 buttons on the page when initiated.

Related

Disable mouse right click in PDF

I am try to load an uploaded PDF file to my view file with an <iframe> tag, How can i disable the mouse right click in that specific <iframe> tag
My code is like this:-
<iframe id="your_iframe_id" src="http://localhost/employee/assets/documents/1582002009.pdf#toolbar=0&navpanes=0&scrollbar=0" onload="injectJS()" readonly="true" style="width:1000px; height:600px;" frameborder="0"></iframe>
<script type="text/javascript">
function disableContextMenu()
{
window.frames["your i frame id"].document.oncontextmenu = function(){alert("No way!"); return false;};
// Or use this
// document.getElementById("your i frame id").contentWindow.document.oncontextmenu
= function(){alert("No way!"); return false;};;
}
</script>
dont remember call this function too. if its not working tell me

IE 11. Why have I click and dblclick events after reload page if I double click a submit button

I have a simple html page and event handlers on submit button and form. Event handler function print to console what is event appers.
<html>
<head>
<script type="text/javascript" src="../js/jquery-2.1.1.js"></script>
</head>
<body>
<form id="formId" method="post">
<input id="inpSbm" name="inpSbm" type="submit" value="SubmitTest" class="lockDoubleClick"/>
</form>
</body>
<script>
$(document).ready(function () {
console.log("on ready");
$(".lockDoubleClick").each(function () {
var btn = $(this);
btn.click(function () {
console.log("click")
});
btn.dblclick(function () {
console.log("double click")
});
btn.closest('form').submit(function () {
console.log("submit form");
});
});
});
</script>
</html>
In IE11 when I double click on submit button I see the following in console:
click
submit form
on ready
click
double click
Why have I click and double click event after page is ready?
Because double-click is one of the most stupid ideas in the history of computing.
There are users who can double-click very quickly. There are others who can barely get in under the time limit that is the only difference between a double click and two singles. This means that when the computer sees the first click it must wait for a very long time to see if the user is going to click again. Users hate this; it makes the interface seem very slow.
The only solution is to have a 'double-click' actually hit the application as two clicks. They are identical except that the second one has a little flag that says it came in under the deadline for a double-click.
If against all reason you must accept both a double-click and a single-click on the same object you MUST be able to reverse the effect of the first click when the second user gets around to actually pushing the button for their very belated double-click.

Google rending +1 button way above and left of page content

We have implemented google +1 buttons on our site and they have served reliably for some time. However we recently noticed that the buttons are not serving reliably. We rarely see them appear in their designated spaces.
For example on this page: Sample Page : you'll see a gray box of social buttons to left of the page. In it, there is SUPPOSED to be a Google +1 button.
We've requested the button with this code:
<div id="social-google" class="social">
<script type="text/javascript">
(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>
<g:plusone size="medium"></g:plusone>
</div>
We've also tried this code:
<div id="social-google" class="social">
<!-- Place this tag where you want the share button to render. -->
<div class="g-plus" data-action="share" data-size="small" data-annotation="bubble"></div>
<!-- Place this tag after the last share tag. -->
<script type="text/javascript">
(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>
</div>
Occasionally we'll see a Google +1 button render but, more often than not, the space reserved for the button is apparently blank. When you examine things with firebug, you see that Google HAS attempted to render a button, but for some reason it has placed the button far above and left of the page boundaries.
Here is the top of the html Google generates for the button:
<div id="___plusone_0" style="position: absolute; width: 450px; left: -10000px;">
<iframe id="I0_1377554650466" width="100%" scrolling="no" frameborder="0" hspace="0 marginheight="0" marginwidth="0" style="position:absolute;top:-10000px;width:450px;margin:0px;border-style:none" tabindex="0" vspace="0" name="I0_1377554650466" src="https://apis.google.com/_/+1/fastbutton?bsv=o&usegapi=1&size=medium&hl=en-US&origin=http%3A%2F%2Fwww.comicbookresources.com&url=http%3A%2F%2Fwww.comicbookresources.com%2F%3Fpage%3Darticle%26id%3D47537&gsrc=3p&ic=1&jsh=m%3B%2F_%2Fscs%2Fapps- ...
As you can see Google gave its generated ___plusone_0 div a left position of -10000px and gave the inner iFrame a top position of -10000px. So the button is there. It's just floating out in space. If I manipulate theses position settings (to 0px) the button becomes visible in its appropriate spot.
Any idea why this would happen? Any idea how we can fix this?
You can try adding the following CSS declaration to your stylesheet:
#___plusone_0, #___plusone_0 iframe {
position:static !important;
}
This is a hackaround, so don't depend on it in long term.
Based on an old thread in Drupal Issues.
During the last few days I'm suffering from this problem too. I have a page building app. One of the widgets is google plus: users can enter a url, and the app generates a button. (So there can be more, than 1 button on the page.) Then user saves the page and can see it on Facebook.
Recommendations and observations...
Double check the protocol of google api script. For example, if your website is on https and you are trying to load http://apis.google.com/js/plusone.js, your buttons will probably fail to render.
When I tested this issue on my server, I occasionally opened the app in 2 browser tabs at the same time. Google buttons didn't appear in the first tab, but they did in the second one!
My app requires user to be authorized on Facebook. When I opened the app without authorization, the buttons were shown as expected. But when I logged in and refreshed the page - buttons disappeared.
When I opened the page on Facebook, buttons didn't appear, regardless of whether I was logged in or not.
I beg your pardon, if you think these notices have no sense, but they may save someone's time in future.
Workaround
Suppose, you're parsing the following code:
<!-- google button will be added into this div -->
<div class="googlePlus" data-href="http://google.com"></div>
jQuery function, which parse all .googlePlus divs.
$('.googlePlus').each(function () {
var $googleDiv = $(this);
// check, if button is already parsed
if (!$googleDiv.children().length) {
// add temporary id to the parent div
var $id = 'googlePlus-' + new Date().getTime();
$div.attr({
'id': $id
});
// create, add and render btn (IE compatible method)
var gPlusOne = document.createElement('g:plusone');
gPlusOne.setAttribute('href', $googleDiv.attr('data-href'));
document.getElementById($id).appendChild(gPlusOne);
gapi.plusone.go($id);
// function, correcting css styles
if (!$.isFunction($.fn.fixGooglePlus)) {
$.fn.fixGooglePlus = function () {
$(this).children('div').children('iframe').addBack().css({
position: 'static',
width: 106,
height: 24
});
}
}
// run function, until css is fixed
var $timer = setInterval(function () {
$googleDiv.fixGooglePlus();
if ($googleDiv.find('iframe').css('position') == 'static') {
clearInterval($timer);
$googleDiv.removeAttr('id');
}
}, 100);
} // button hasn't been parsed
});
Put the button code in a a new HTML file and put that file in an iframe. Compared to #U-D13's answer, it's less susceptible to changes by Google.

Invalid value for property <position> with two level iframe context

I'm having problem setting marker position and map center, with "Invalid value for property " error or "invalid value for property " error such as:
Error: Invalid value for property : (13.7323691218542,
100.64347976627096) Source File:
http://maps.gstatic.com/intl/en_us/mapfiles/api-3/13/5/main.js Line: 26
This is based on tests on Firefox and Chrome
My top HTML contains:
Javascript function "move_it()"
An iframe (id: "mapIframe") sourced by a cgi (nwfMap.cgi)
And the "mapIframe" iframe cgi contains:
A var mapNwf for a map
A var markerMe for a marker
An iframe (id: "myInfoIframe") sourced by a cgi (nwfSetInfo.cgi)
And the "myInfoIframe" iframe cgi contains:
A call to the function "move_it()" defined in top HTML
This call is intended to move the marker (markerMe) to a specific location
and also to set the map (mapNwf) center to the same specific location
The invocation of the "move_it" was executed OK until when it tried to do:
mrk.setPosition(pos); or
mp.setCenter(pos);
It's here I've encountered the "Invalid value for property ..." errors.
The immediately preceding execution were of:
alert('mp = [' + mp.getCenter() + ']'); and
alert('mrk = [' + mrk.getPosition() + ']');
were OK with correct location (lat/lng) value displayed (map center and marker position)
So the question is, how come getCenter and getPosition worked for same map and marker variables, but the setCenter and setPosition had failed?
If getCenter and getPosition came back with correct data, it indicates that there's no variable context issues, right?
But then how come I can only "read" but not "set" the values via these variables?
Would it be related to the appearance of the google line:
in the top HTML, and in its iframe, and in the iframe's iframe?
Repetition and the nested level causing some google map context issue leading to my problem?
Much thanks in advance for any advice! Followings are relevant code portions for your examination and investigation:
Relevant portions of the top HTML
<html>
........
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
<script language="JavaScript">
function move_it(slat, slng) {
var ifrm = document.getElementById('mapIframe');
var mp = ifrm.contentWindow.mapNwf;
var mrk = ifrm.contentWindow.markerMe;
var pos = new google.maps.LatLng(slat,slng);
alert('mp = [' + mp.getCenter() + ']');
alert('mrk = [' + mrk.getPosition() + ']');
alert('pos = [' + pos + ']');
mrk.setPosition(pos);
mp.setCenter(pos);
}
</script>
.........
<div id="nwfMap">
<iframe width=100% height=520 frameBorder=0 src="nwfMap.cgi" name="mapIframe" id="mapIframe" scrolling=no></iframe>
</div>
........
</html>
Relevant portions of the "mapIframe" iframe (produced by nwfMap.cgi)
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var mapNwf = new google.maps.Map(document.getElementById('mapCanvas'), {
zoom: 8,
mapTypeId: google.maps.MapTypeId.HYBRID
});
var latLngPre = new google.maps.LatLng(0.0, 0.0);
var markerMe = new google.maps.Marker({
position: latLngPre,
title: 'Me Here',
map: mapNwf,
draggable: true,
animation: google.maps.Animation.DROP
});
.........
</script>
.........
<div id="myInfoForm" style="display: none;">
<iframe border=1 width=100% height=200 align=center marginwidth=0 marginheight=0 seamless=seamless frameBorder=0 src="nwfSetInfo.cgi" name="myInfoIframe" id="myInfoIframe" scrolling=no></iframe>
</div>
.........
Relevant portions of the "myInfoIframe" iframe (produced by nwfSetInfo.cgi)
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript">
parent.parent.move_it(13.7323691218542, 100.643479766271);
</script>
The problem is fixed now, by moving the "move_it()" function definition down from the top level HTML to the mid-level iframe "mapIframe" and by changing the "move_it()" invocation in the "myInfoIframe" iframe from
parent.parent.move_it(13.7323691218542, 100.643479766271);
to
parent.move_it(13.7323691218542, 100.643479766271);
Don't know why, but obviously by the reducing of invocation context level something got corrected on the original "can read but not write on map variable" problem. If any one has a good explanation, would like to hear about it. Thanks.

How to add id using dojo.query to search element

I'm trying to add id to a element using dojo.query. I'm not sure if it's possible though. I trying to use the code below to add the id but it's not working.
dojo.query('div[style=""]').attr("id","main-body");
<div style="">
content
</div>
If this is not possible, is there another way to do it? Using javascript or jquery? Thanks.
Your way of adding an id to an element is correct.
The code runs fine for me in Firefox 17 and Chrome 23 but I have an issue in IE9. I suspect you may have the same issue.
In IE9 the query div[style=""] returns no results. The funny thing is,it works fine in compatibility mode!
t seems that in IE9 in normal mode if an HTML element has an inline empty style attribute, that attribute is not being preserved when the element is added to the DOM.
So a solution would be to use a different query to find the divs you want.
You could try to find the divs with an empty style attributes OR with no style attribute at all.
A query like this should work:
div[style=""], div:not([style])
Take a look at the following example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Page</title>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.8.2/dojo/dojo.js"></script>
<script type="text/javascript">
dojo.require("dojo.NodeList-manipulate");//just for the innerHTML() function
dojo.addOnLoad(function () {
var nodeListByAttr = dojo.query('div[style=""], div:not([style])');
alert('Search by attribute nodeList length:' + nodeListByAttr.length);
nodeListByAttr.attr("id", "main-body");
var nodeListByID = dojo.query('#main-body');
alert('Search by id nodeList length:' + nodeListByID.length);
nodeListByID.innerHTML('Content set after finding the element by ID');
});
</script>
</head>
<body>
<div style="">
</div>
</body>
</html>
Hope this helps
#Nikanos' answer covers the query issue, I would like to add, that any query returns an array of elements, in case of Dojo it is dojo/NodeList.
The problem is you are about to assign the same id to multiple DOM nodes, especially with query containing div:not([style]). I recommend to use more specific query like first div child of body:
var nodes = dojo.query('body > div:first-child');
nodes.attr("id", "main-body");
To make it more robust, do not manipulate all the nodes, just the first node (even through there should be just one):
dojo.query('body > div:first-child')[0].id = "main-body";
This work also in IE9, see it in action: http://jsfiddle.net/phusick/JN4cz/
The same example written in Modern Dojo: http://jsfiddle.net/phusick/BReda/