Wordpress is not loading jquery - I think it may have something to do with the fact that it is loading the files absolutely, not relatively, and it won't go to the url (firebug is saying access denied to restricted uri). I have tested vanilla javascript and that works, however as soon as i try to do even the most basic function in $(document).ready(function(){}) it stops working.. is there a way to stop wordpress from appending the website uri to the linked files, and reference them relatively instead, as i think this may fix it.
The outputted head is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>simplespace — not quite ready yet</title>
<meta name="generator" content="WordPress 3.0.1" /> <!-- leave this for stats -->
<link rel="stylesheet" href="http://simplespace.co.nz/wp-content/themes/blass2/style.css" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://simplespace.co.nz/feed/" />
<link rel="alternate" type="text/xml" title="RSS .92" href="http://simplespace.co.nz/feed/rss/" />
<link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="http://simplespace.co.nz/feed/atom/" />
<link rel="pingback" href="http://simplespace.co.nz/xmlrpc.php" />
<link rel="shortcut icon" href="http://simplespace.co.nz/wp-content/themes/blass2/favicon.ico" />
<link rel='archives' title='September 2010' href='http://simplespace.co.nz/2010/09/' />
<link rel='stylesheet' id='sociable3-css' href='http://simplespace.co.nz/wp-content/plugins/sociable-30/sociable.css?ver=5.10' type='text/css' media='all' />
<script type='text/javascript' src='http://simplespace.co.nz/wp-includes/js/jquery/jquery.js?ver=1.4.2'></script>
<script type='text/javascript' src='http://simplespace.co.nz/wp-content/plugins/wordpress-flickr-manager/js/jquery.lightbox.js?ver=3.0.1'></script>
<script type='text/javascript' src='http://simplespace.co.nz/wp-content/plugins/wordpress-flickr-manager/js/wfm-lightbox.php?ver=3.0.1'></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://simplespace.co.nz/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://simplespace.co.nz/wp-includes/wlwmanifest.xml" />
<link rel='index' title='simplespace' href='http://simplespace.co.nz/' />
<meta name="generator" content="WordPress 3.0.1" />
<script type="text/javascript" src="http://simplespace.co.nz/wp-content/plugins/audio-player/assets/audio-player.js?ver=2.0.4.1"></script>
<script type="text/javascript">AudioPlayer.setup("http://simplespace.co.nz/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1", {width:"400",animation:"yes",encode:"yes",initialvolume:"60",remaining:"no",noinfo:"no",buffer:"5",checkpolicy:"no",rtl:"no",bg:"dcf2fa",text:"333333",leftbg:"dcf2fa",lefticon:"333333",volslider:"666666",voltrack:"cfcfcf",rightbg:"9ee1f7",rightbghover:"dcf2fa",righticon:"333333",righticonhover:"333333",track:"FFFFFF",loader:"9ee1f7",border:"CCCCCC",tracker:"dcf2fa",skip:"666666",pagebg:"FFFFFF",transparentpagebg:"yes"});</script>
<!-- WFM INSERT LIGHTBOX FILES -->
<link rel="stylesheet" href="http://simplespace.co.nz/wp-content/plugins/wordpress-flickr-manager/css/lightbox.css" type="text/css" />
<!-- WFM END INSERT -->
<script type='text/javascript'>
$(document).ready(function() {
alert('test');
});
</script>
</head>
Wordpress puts jQuery in no-conflict mode which disabled the $() function. Unless you disable no-conflict mode in jQuery you'll have to use jQuery() instead of $().
Try this:
Full answer for those who are facing same problem
You can wrap your javascript inside a self-invoking function, then pass jQuery as an argument to it, using $ as the local variable name. For example:
(function($) {
$(document).ready(function(){
alert('test');
});
}(jQuery));
The jQuery library included with WordPress is set to the noConflict() mode. This is to prevent compatibility problems with other JavaScript libraries that WordPress can link.
In the noConflict() mode, the global $ shortcut for jQuery is not available.
I looked at the site and jquery is loading. This:
<script type='text/javascript'>
$(document).ready(function() {
alert('test');
});
</script>
wont work because WordPress uses jquery in no conflict mode. This:
jQuery(document).ready(function($){
alert('test');
});
is how it should be called in no conflict mode. Also the lightbox plugin is throwing an error:
Uncaught TypeError: Object # has no method 'lightBox'
Related
In order to get a mobile nav menu working I've got this Javascript block:
function AddMobileNavMenu() {
var $body = $('body')
$(
'<div id="navPanel">' +
$('#nav').html() +
'' +
'</div>'
)
.appendTo($body)
.panel({
delay: 500,
hideOnClick: true,
hideOnSwipe: true,
resetScroll: true,
resetForms: true,
side: 'left'
});
}
But I can't get that javascript working with Blazor - I've read through all the JSInterop documentation and figured out that this (in the _Host.cshtml file):
#page "/"
#namespace FIS2.Pages
#addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>FIS2</title>
<base href="~/" />
<link rel="stylesheet" href="FontAwesome/scss/fontawesome.min.css" />
<link rel="stylesheet" href="FontAwesome/scss/solid.min.css" />
<link rel="stylesheet" href="FontAwesome/scss/regular.min.css" />
<link rel="stylesheet" href="css/syncfusion/syncfusionTheme.css" />
<link rel="stylesheet" href="css/site/Components/site.min.css" />
</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />
<script src="_framework/blazor.server.js"></script>
<script src="Scripts/jquery-3.6.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>
<script src="Scripts/AddMobileNavMenu.js"></script>
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
Reload
<a class="dismiss">🗙</a>
</div>
</body>
</html>
Allows you to call it from the relevant component, like so:
await jsRuntime.InvokeVoidAsync("AddMobileNavMenu");
So long as you've injected IJSRuntime
The only problem is that it doesn't seem to be loading in the jQuery and triggers an error saying appendTo is not a function. What am I missing in order to make this work?
Looking at the issue with fresh eyes, I've realised my mistake - it turns out that it wasn't complaining about appendTo, but rather panel. I hadn't realised that was part of another library - importing that library after jquery (but before the custom function) solved the issue.
I'll leave the question here in case someone else goes down the train of thought that I did on Friday.
This is my .cshtml code
<!DOCTYPE Html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>welcome</title>
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.8.0.min.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
</head>
<body>...</body>
</html>
Whenever I execute my code it gives the bootstrap requires jquery error. Please suggest what should I do to remove this error.
Make sure that the path is correct and points to jQuery version greater than 1.9
You are using 1.8 which is not compatible with bootstrap
Source:
https://github.com/twbs/bootstrap/blob/v3.1.1/bower.json
Just as Amit Joki said, make sure you link points directly to the jquery file and
the file name is spelt accordingly.
Also ensure that you link jquery js script before you link to the bootstrap js script
<script src="path_to_script/jquery-1.8.0.min.js"></script>
<script src="path_to_script/bootstrap.js"></script>
<link href="path_to_script/bootstrap.css" rel="stylesheet" />
I'm going to use bootstrap to build up my front end. Also I'm using JSP and JSTL
What I've read in some articles over the internet is the proper approach of adding an external javascript file should be written before the body closing tag for more optimization of the page. Now I'm trying to apply this with the bootstrap, what i did is put the css of the bootstrap to an external html file:
import_header.html:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="bootstrap-css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="bootstrap-css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="bootstrap-css/bootstrap-responsive.css">
<link rel="stylesheet" type="text/css" href="bootstrap-css/bootstrap-responsive.min.css">
which I imported to the head of the html like this:
<jsp:include page="import_header.html" flush="true" />
Now I want to do the same thing with the js file of the of the bootstrap and the jQuery lib but I don't know what is the proper way of doing this.
that's the recommended way, how to place them:
e.g. footer.html
<!-- Placed at the end of the document so the pages load faster -->
<script src="jquery/jquery-2.0.3.min.js"></script>
<script src="bootstrap/bootstrap-2.3.1.min.js"></script>
<script src="myOwn.js"></script>
</body>
</html>
I'm trying to implement swiping of image using html and javascript for phonegap application, following this demo PhotoSwipe there it works fine, but after adding into my project, not able to swipe the images. and even linked the js files correctly still i get this error in logcat "Uncaught TypeError: Cannot read property 'PhotoSwipe' of undefined at file:///android_asset/www/examples/01-default.html:26"
any idea on my issue? Thanks.
swipe code
<title>PhotoSwipe</title>
<meta name="author" content="Ste Brennan - Code Computerlove - http://www.codecomputerlove.com/" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<link href="styles.css" type="text/css" rel="stylesheet" />
<link href="css/photoswipe.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" charset="utf-8" src="js/cordova-1.9.0.js"></script>
<script type="text/javascript">
<script type="text/javascript">
(function(window, PhotoSwipe){
document.addEventListener('DOMContentLoaded', function(){
var
options = {},
instance = PhotoSwipe.attach( window.document.querySelectorAll('#Gallery a'), options );
}, false);
}(window, window.Code.PhotoSwipe));
</script>
<script type="text/javascript" src="js/cordova-1.9.0.js"></script>
<script type="text/javascript" src="/libs/klass.min.js"></script>
<script type="text/javascript" src="js/code.photoswipe.jquery-3.0.5.min.js"> </script>
<script type="text/javascript" src="js/code.photoswipe.jquery-3.0.5.js"></script>
<script type="text/javascript" src="js/code.photoswipe-3.0.5.min.js"></script>
<script type="text/javascript" src="js/code.photoswipe-3.0.5.js"></script>
<script type="text/javascript" src="photoswiper.js"></script>
}
Add the js files before the script that you have written, it might be the cause of the problem because the photoswipe features that you are trying to use in the script have not been loaded and hence are not available yet.
I'm just posting my entire page to prevent confusion. I've stared at each link and checked the folder for the files. it all seems to be there. what's not working? very frustrated, could use a fresh pair of eyes. all my page displays is the content of the pre, but without any formatting. again, thanks for the help
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--STYLESHEET LINKS-->
<link href="stylesheet.css" rel="stylesheet" type="text/css" media="screen" />
<link href="shThemeDefault.css" rel="stylesheet" type="text/css" media="screen" />
<link href="shCore.css" rel="stylesheet" type="text/css" media="screen" />
<!--SYNTAX HIGHLIGHTER-->
<script type="text/javascript" src="shCore.js"></script>
<script type="text/javascript" src="shBrushPhp.js"></script>
<!--JQUERY and PROCESSING SCRIPTS-->
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery-ui.js"></script>
<script type="text/javascript" src="processing.js"></script>
<script type="text/javascript" src="init.js"></script>
</head>
<body>
<pre class="brush: php">
$last_modified = filemtime("header.php");
echo("last modified: ");
echo(date("m.j.y h:ia", $last_modified));
</pre>
<script type="text/javascript">
SyntaxHighlighter.HighlightAll();
</script>
</body>
</html>
Four things:
SYNTAX HIGHLIGHTER - put the .js files AFTER the jquery, jQueryUI, etc. scripts. The order is important!
use $(document).ready to make sure that all the js files are loaded before the body content tries to use it.
Are you using firebug or some such tool to check for script errors in the browser?
Are you getting any errors at all or just not seeing the highlighting effect?
By replacing:
SyntaxHighlighter.HighlightAll();
with
SyntaxHighlighter.all();
your sample code works for me.