I'm conditionally loading a script if the browser is IE8. I'm using jquery's .getScript function because I need to run something after the script is loaded. The problem is in the format of the URL. I've got it working when downloading the script that's on my hard drive directory but I can't get it to work when loading the script from a site.
This is what I have, I'm sure it's a simple fix but I'm not getting it to work:
$.getScript("https://github.com/malsup/corner/blob/master/jquery.corner.js", function () {
//does something here
});
Thanks for your fix.
The problem is that you are requesting the actual formatted github page ... so you get back html..
use
$.getScript("https://raw.github.com/malsup/corner/master/jquery.corner.js", function () {
//does something here
});
(changed the url to the correct one..)
There is a link Raw on the heading bar above the formatted code. Click it to get to the raw file..
The safe url is http://malsup.github.com/jquery.corner.js
Related
I am trying to automatically download a plugin on my wordpress site by implementing phantomJs. For some reason, I cannot seem access the download button (shown below)
This is the HTML code to the image (with domain sensitive information blurred out for security purposes)
So far, I have tried accessing this element by using the following code:
function() {
page.evaluate(function() {
let mainLink = document.querySelector('a[data-slug="better-wp-security"]')
mainLink.click()
})
}
Some things to mention:
This function, as it is part of a larger file, will NOT execute until the page has finished loading.
PhantomJS is executing correctly, there are no problems with permissions
The script before-hand is properly accessing the install plugins page, which I verified by capturing screenshots before trying to click.
I have defined click earlier int he file, it works perfectly.
Any ideas how I can accomplish this? Thanks all!
ADDED INFORMATION:
It seems as if the path from the main div element is as follows:
#the-list .plugin-card plugin-card-better-wp-security .plugin-card-top .action-links .plugin-action-buttons .install-now button
I imagine the solution to this question has something to do with this sequence.
I was able to accomplish this by now going after the data-slug attribute, but rather going after the href element itself. Although I can't generate my own wponce value without the use of the Rest API, I was able to search the document to find an href that contained certain parts of the url. This is the final code below:
document.querySelector('a[href*="action=install-plugin&plugin=better-wp-security"]').click()
That's it! Simple and easy!
I'm trying to load an external script while using Meteor.
Currently using this code in my layout.js to some success.
Meteor.startup( function() {
$.getScript('js/scripts.js');
});
However, if I go to another url and come back to it, the script no longer works. (I see it not working because my background cover image disappears.)
Any external scripts should be placed in client/compatibility, and Meteor will load it for you; no need for $.getScript('js/scripts.js');
You can then instantiate that script on the template like:
Template.game.onRendered(function(){
$('.grid').isotope({});
});
For anyone needing help with this, replace Meteor.startup with Template.name.onRendered. This helped solve my issue.
Cheers!
I have an javascript that I place into a page using the code below. What the code does is place an object/embed code into a webpage. Simple javascript loader to a NicoVideo movie
<script type="text/javascript" src="http://ext.nicovideo.jp/thumb_watch/sm13154955?w=640&h=395"></script>
This works great in a webpage. But what if I want to load this javascript into a page using AJAX? This no longer works for the obvious reasons, you would need to eval the script in order to get it to run. However, I have no idea how to do this. I am using jQuery on my page; so keep that in mind. I have tried the following code, but it doesn't seem to work through AJAX, or even in a normal page load environment.
<script>$.getScript("http://ext.nicovideo.jp/thumb_watch/sm13154955?w=640&h=395");</script>
Any ideas on how I would get this to work?
I think it works but its attempting to inline the write which I don't know if that would work in this case.
You would need to see if there was a way to essentially execute the '.getHTML' method and take that result and update an existing element on the page.
The issue though is that the anonymous function that is generated and executed inline might not work properly.
After reading official getScript reference, it seems you have to do something with that JS file you got a hold of, using something like this:
$.getScript("http://ext.nicovideo.jp/thumb_watch/sm13154955?w=640&h=395", function () {
// use functions from loaded file
});
I have encountered a problem. When I use jQuery to load a page that contains heavy javascript, the page freezes. I believe it is because the js executes before the page loads as my local site does not freeze. However, $(document).ready(function(){}); seems not working with dynamically loaded pages? is that true? or anything i could do to solve this problem. Thanks a million!
$(document).ready() works fine in dynamic pages. There must be an error in your code somewhere.
The first thing to do is to try View Source and save the HTML to a plain .html file, then load that file in your browser. If that still fails then you know the problem has nothing to do with the server-side ASP/PHP/whatever code. Then try removing HTML and JavaScript piece by piece until the problem disappears. That'll help you narrow down the culprit line(s). If you can reduce your page to a small file that still demonstrates the problem, post that here and we'll try to help.
Try using
$(window).load(function(){
dosomething();
});
It will run the js after the whole page is loaded.
Avoid using
$(document).ready(function(){
dosomething();
});
It will run the js just after the loading of DOM.
I'm working on a site that relies on quite a bit of javascript. The problem is, I'm not a javascript guru in the least. Yes, bit off more than I can chew, here.
I'm using jquery for a spy effect, and use GetResponse for email signups.
If I implement my GetResponse script, it breaks the area later in the page which depends on the jquery script. Pull the GetResponse script and it works just fine.
Problem is, I need them both. ;)
The trick, I suppose, is that the GetResponse script is actually another Jquery script, so it's getting called twice...
Any help?
The site is http://djubi.com/testserver
Check out (urlabove)/nogetresponsescript.php to see it work without the GetResponse script. You should be able to see all the source just fine.
Thanks everyone. jf
GetResponse includes jQuery and is overwriting your plugin ($.fn.simpleSpy) when it loads jQuery again. So what you can try to do is wrap your plugin and initialization in $(document).ready(). For example:
$(document).ready(function() {
(function($) {
$.fn.simpleSpy = function (limit, interval) {
// snipping code out
};
})(jQuery);
$(function() {
$('ul.spy').simpleSpy();
});
});
I pasted your code for simpleSpy into Firebug after the page loaded, and it seemed to work. If $(document).ready() doesn't work, you might want to try $(window).load().