Third party script wont load until page refresh - javascript

I run into a problem with my blog that I've been writing content for months now. I'm using Gatsby v2 and the Netlify CMS v2 and host the entire blog with the help of Netlify and Github.
I've asked for help a few days ago but the thread got deleted due to not enough clarification.
So, I'm trying again now.
I'm using this starter: https://github.com/thriveweb/yellowcake , and haven't changed much besides CSS yet.
I'm trying to improve my blog by updating the /src/templates/SinglePost.js template for all my blog posts by adding share buttons from Addthis.com. I've successfully added their code (script) to my blog:
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-545927b3c48573a"></script>
by using Netlifys Snippet injection option. This option allows to inject analytics or other scripts into the HTML of the site before </body> tag.
but since its a static website, If I enter the website from the home URL it doesn't load the script on other pages. I have to refresh (reload) the blog post in order to see the share buttons if I'm coming from the homepage or any other page from the website. Is there a way to refresh the blog posts automatically when a user enters the blog post when he's coming from the homepage?
Looking for solutions :)

You can try something like
<body onload="addScript()">
function addScript() {
var my_script = document.createElement('script');
my_script.setAttribute('src','http.....');
document.head.appendChild(my_script);
}

Related

Loading a specific div from another website into own website

Ive tried using the js load function but as the external site does not allow CORS requests, my original GET request gets blocked.
<div id="test"></div>
<script>
$(document).ready(function () {
$("#test").load("https://mywebsite.com");
});
</script>
So it seems that my only approach is to use iframes?! Is there a way to only crawl a specific div with iframes? I dont want to display the whole website.
EDIT: Since I am using Django I was able to crawl the website with python in a view and then push the crawled and cleaned up code snippet in the html template. Nevertheless to answer my question -> There is no correct way of doing it as long as the website you are trying to access is blocking the content.
Work with the owner of the site you want to take content from.
They can set you up with an API. That avoids having to use hackey methods or risking copyright-related legal trouble.

Google does not showing my page in search results when I use js src to get content from php page

in the name of GOD. I have a js code in a page in website 1, for showing content.
<script id="mdval" src="http://web1.com/api/pc.php" type="text/javascript" dval="sourceval">
with this method I received articles and news from database in website 2 in other server.
I dont have any problem about receiving content from website 2 and News and articles showing is very good in website 1 page. But problem is here that Google not showing website 1 page in search results. I test it in Google search after a month, but not shows the page.
Please note that I can use just client side methods with AJAX.
UPDATE:
I tested page in Fetch as Google tool. I selected fetch and render for a page that uses ajax. googlebot saw the page just like visitors with all contents and images. I click on "submit to index" for indexing page. Now after one day I searched URL in google and google listed it.
But Now problem is here that google just shows url and meta description in search results and not shows any content of the page.
please search this link in google. www.neginkoodebasir.ir/more?naapi= گیاهان مورد استفاده در تهیه کود سبز (بخش دوم)
image 1
image 2
The google bot crawler does not parse your data that come from Ajax, it's only crawl the source of the page (CTRL + U on Chrome Windows).
Try to see with https://developers.google.com/webmasters/ajax-crawling/docs/learn-more
You can also try to put the data from your PHP script on cache and load the cache.
And every X hours, reload the cache.
Try to see with this tool : support.google.com/webmasters/answer/6066468?hl=en
it seems that Google CAN crawl your scripts: "Times have changed. Today, as long as you're not blocking Googlebot from crawling your JavaScript or CSS files, we are generally able to render and understand your web pages like modern browsers. To reflect this improvement, we recently updated our technical Webmaster Guidelines to recommend against disallowing Googlebot from crawling your site's CSS or JS files." https://developers.google.com/webmasters/ajax-crawling/docs/learn-more
Try to see with this tool: support.google.com/webmasters/answer/6066468?hl=en

DotNetNuke include javascript on every page

I want to create a module that basically includes javascript on to every page on a dotnetnuke site. I can include a js file in the current page,
ClientResourceManager.RegisterScript(this.Page,
"~/DesktopModules/AuthenticationServices/ZapperScanToLogin/view.js",
FileOrder.Js.jQuery);
but what I really want to do is install my module on the home page and it will include javascript on to every page on the dnn site. Is this possible, how can I do it?
I would honestly do this with a modification to your skin, but here are the steps to do it with a module.
Create a module (I recommend starting with my templates http://christoctemplate.codeplex.com)
Add your JS code
Add the module to the homepage
Go to the module settings, choose Display on All Pages
I would add this to your skin, either just manually by adding the reference, or by creating a SkinObject rather than a module.
If you do it as a module it is possible that a user can delete the module from the page, or a number of other things. if this script is a requirement it is best to make it so that users can't break the site by doing something accidentally.
One way to do it is add to the header of the site, under site settings. Logged in as SuperUser:
Go Settings (Cog) Site Settings
Site behavior Tab - Default Pages
At the bottom: Page Output Settings
HTML Page Header Tags: add your script link:
Sample below. Does not show up at bottom of page, shows up top in header, but will be on every page.
<script type="text/javascript" src="/Portals/0/Your-js-here.js"></script>
There ought to be a page template for your module which you can edit and insert the jQuery script reference into the header of (in between the <head> tags). This would then be loaded on each page of the module.
Here are a couple of references that might help:
http://wnsinj.codeplex.com/
http://www.dnnsoftware.com/community-blog/cid/135141/DotNetNuke-Tips-and-Tricks-11-Using-jQuery-in-DotNetNuke
What I ended up doing was including a javascript registration in the js/debug/dnn.modalpopup.js file, which then registers my javascript on the login and registration pages and popup dialogue boxes.
var myView = document.createElement("script");
myView.type = "text/javascript";
myView.src = "/js/view.js";
var myTech = document.createElement("script");
myTech.type = "text/javascript";
myTech.src = "/js/mytech.js";
document.head.appendChild(myView);
document.head.appendChild(myTech);
I am not sure placing the javascript files in that location is ideal or not, but this is the solution that works for me. I think the manual dev work per DNN site will be minimal so I hope it's an acceptable solution.
I am not sure whether I should put the script in the page head, or the body... the order of loading and what not of javascript is a mystery to me.

Linking to detail pages in Rally custom apps

I have been using the following code to insert a hyperlinked FormattedID into my grid. I can't use the standard formatting template because my grid has both User Stories and Features. When I click one of the links it takes me to a blank page (with the Rally wrapper). If I copy and paste the URL into the nav bar everything works perfect so I know the link isn't bad. The error the page is throwing is "TypeError: mainWindow.Rally.alm is undefined".
var idLink = i.get('FormattedID');
if (idLink.match('US')) idLink = '' + idLink + '';
else if (idLink.match('F')) idLink = '' + idLink + '';
Also, if I take out the "target='_blank'" option the details page loads fine. But I would rather leave it in since my apps run within an iframe. It looks a little silly having a Rally page (wrapper and all) load within another Rally page. Any help would be appreciated!
We currently know this is a pretty big hole in our public API. The unreleased head revision of the SDK has better support for rending links in apps (Rally.util.DetailLink).
Look for it in the next preview version of the SDK and/or the GA.
Unfortunately this isn't a supported use case detail pages, although I can certainly see how this would be a useful page rendering option.
I'd recommend posting this as an Idea out on Rally Ideas, so that other Rally customers can vote on it and gain visibility and traction as a feature request in the product.

facebook comments - doesn't let me moderate

I'm trying to install facebook comments on my page, but it doesn't let me moderate. On a test page with only the comments plugin - no problem. the same code exactly on a live page - doesn't let me moderate.
the test page:
http://www.radicalislam.org/test3.html
the live page:
http://www.radicalislam.org/news/pakistan-hands-huge-prison-sentence-bin-laden-informant
tried to debug, it shows the right admin and app id.
it's a drupal site, if it's important
Looks like you are using partial URLs for the href. Use the full one.
Use the following instead.
<div class="fb-comments" href="http://www.radicalislam.org/news/pakistan-hands-huge-prison-sentence-bin-laden-informant" data-num-posts="5" data-width="580"></div>
Unfortunately my work Firewall wouldn't let me click through to the link.
Are you using the correct URL when you add the Facebook comments to the page? If you aren't you won't be able to moderate, you will likely need to dynamically add the URL to the generated code.
Have you tried scraping the page using the debug tool (as the admin)?
http://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.radicalislam.org%2Ftest3.html
This will read the updated admin IDs and let the administrator see the moderation panel in the plugin and via https://developers.facebook.com/tools/comments

Categories