I am trying to include Facebook's Javascript SDK (the all.js file from http://connect.facebook.com/en_US/all.js) dynamically vis javascript for my web app. I have used the following code.
$.getScript('http://connect.facebook.com/en_US/all.js', function() {
alert('Facebook script has loaded');
});
When this is executed, currently I find that the page never alerts. My main aim is to load the Facebook JS SDK programatically. Kindly let me know if there is something wrong in what I am doing or is there any other way to achieve it.
The url is wrong, change to:
'http://connect.facebook.net/en_US/all.js'
Also see this jsfiddle.
Related
If you take a look at this page http://manvanstage.com.s3-website.eu-west-2.amazonaws.com/ and right click on it and choose "View page source" you will find for example the text "100s Man With Van Providers" inside <script type="text/javascript"> instead of inside inside an HTML tag.
These tags are sent by the back-end API to the front-end (Nuxt.js/vue.js)
I tried to use Vue.js lifecycle created and mounted.
What I'm doing wrong?
I know this is bad for SEO.
Update:
Part of this web page I used no-ssr. Do you think this maybe the cause of the issue?
I used npm run build and deploy the application on Node.js severer.
maybe you should check mode property is correctly set 'universal' in nuxt.config.js
https://nuxtjs.org/api/configuration-mode/
Update:
I think it is because you fetch data in created or mounted so they are still not server-side rednder
if you want show something content in source to imporve SEO then fetch your data in asyncData()
example:
before
created(){
this.getSomethingFromAPI()
}
after
asyncData(){
this.getSomethingFromAPI()
}
I am using the jsplumbtoolkit framework in order to load in several script html templates into my meteorjs application in order to create the appropriate divs/dialogues options necessary as a part of the api. After some troubleshooting I determined the issue seemed to be that Meteorjs was not loading my html script through the onRendered function that I supplied it with.
To give you a better idea of the problem
//Due to Meteorjs not able to load scripts directly in the template, I added the script load to my onRendered function in my template js
Template.mytemplate.onRendered(function(){
$(document).ready(function() {
var script = document.createElement("script");
script.type="text/x-jtk-templates";
script.src = "templates/workflowtemplate.html";
$("#rulesscripttemplate").replaceWith(script);
});
})
workflowtemplate.html is in the appropriate meteorjs directory /public/templates/workflowtemplate.html and I am assuming the directory is correct.
This is properly loaded when I check my client Mozilla developer kit as well
<script type="text/x-jtk-templates" src="templates/templaterulesworkflow.html"></script>
Is there a better way to confirm that this resource was infact loaded to the client through mozilla?
Figured it out. had to add the <script type="text/x-jtk-templates" src="templates/templaterulesworkflow.html"></script> to the tag of my application. That resolved the issue.
This question already has answers here:
getting the raw source from Firefox with javascript
(3 answers)
Closed 8 years ago.
I'm not using Selenium to automate testing, but to automate saving AJAX pages that inject content, even if they require prior authentication to access.
I tried
tl;dr: I tried multiple tools for downloading sites with AJAX and gave up because they were hard to work with or simply didn't work. I'm resorting to using Selenium after trying out WebHTTrack (whose GUI wasn't able to start up on my Ubuntu machine + was a headache to provide authentication with in interactive-terminal mode), wget (which didn't download any of the scripts of stylesheets included on my page, see the bottom for what I tried with wget)... and then I finally gave up after a promising post on using a Mozilla XULRunner AJAX scraper called Crowbar simply seg-faulted on me. So...
ended up making my own broken thing in NodeJS and Selenium-WebdriverJS
My NodeJS script uses selenium-webdriver npm module which is "officially supported by the main project" to:
provide login information + do necessary button-clicking & typing for authentication
download all JS and CSS referenced on target page
download target page with original JS/CSS file links change to local file paths
Now when I view my test page locally I see double of many page elements because the target site loads HTML snippets into the page each time it's loaded. I use this to download my target page right now:
var $;
var getTarget = function () {
driver.getPageSource().then(function (source) {
$ = cheerio.load(source.toString());
});
};
var targetHtmlDest = 'test.html';
var writeTarget = function () {
fs.writeFile(targetHtmlDest, $.html());
}
driver.get(targetSite)
.then(authenticate)
.then(getRoot)
.then(downloadResources)
.then(writeRoot);
driver.quit();
The problem is that the page source I get is the already modified page source, instead of the original one. Trying to run alert("x");window.stop(); within driver.executeAsyncScript() and driver.executeScript() does nothing.
Perhaps using Curl to get the page (you can pass authentication in the command) will get you the bare source?
Otherwise you may be able to turn off JavaScript on your test browsers to prevent JS actions from firing.
I want to fetch some information from a website using the phantomjs/casperjs libraries, as I'm looking for the HTML result after all javascripts on a site are run. I worked it out with the following code from this answer:
var page = require('webpage').create();
page.open('http://www.scorespro.com/basketball/', function (status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
var p = page.evaluate(function () {
return document.getElementsByTagName('html')[0].innerHTML
});
console.log(p);
}
phantom.exit();
});
And I also worked it out to get phantomjs/casperjs running on heroku by following these instructions, so when I now say heroku run phantomjs theScriptAbove.js on OS X terminal I get the HTML of the given basketball scores website as I was expecting.
But what I actually want is to get the html text from within a Mac desktop application, this is the reason why I was looking for a way to run the scripts on a web server like heroku. So, my question is:
Is there any way to get the HTML text (that my script prints as a result) remotely within my Objective-C desktop application?
Or asked in another way: how can I run and get the answer of my script remotely by using POST/GET?
p.s.
I can handle with Rails applications, so if there's a way to do this using Rails - I just need the basic idea of what I have to do and how to get the phantomjs script to communicate with Rails. But I think there might be an even simpler solution ...
If I understand you correctly you're talking about interprocess communication - so that Phantom's result (the page HTML) can somehow be retrieved by the app.
per the phantom docs, couple options:
write the HTML to a file and pick up the file in your app
run the webserver module and do a GET to phantom, and have the phantom script respond with the page HTML
see http://phantomjs.org/api/webserver/
i am writing an Adobe Air application using flex builder.the application loads a URL using HTML control and URLLoader.
the problem that the page has an instant redirection JavaScript that redirects the page to another one. I would like to disable that redirection.
I think this can be achieved either by disabling JavaScript on page load or telling the HTML control that do not follow the direction. i don't know how to do that?
thank you so much.
hey, i found a solution to load html source for a remote html document without loading it in htmlloader.so the javascript will not redirect me.
here is the code (from htmlscout sample application of adobe dev).
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,
function(e:Event):void
{
trytogetsource.text = loader.data;
});
loader.load(new URLRequest("http://www.google.com"));