I am having a javascript file named _report_js.html.erb file under app/views/reports. WHen I run my application, I am getting the error:
TypeError: $.url is not a function
This is my code:
<script type="text/javascript">
if($.url().param('ig') == 'true') {
alert("hi");
$('#icons').hide();
$('#photos').show();
end
</script>
I am having a javascript file named _report_js.html.erb file under app/views/reports. WHen I run my application, I am getting the error:
TypeError: $.url is not a function
This is my code:
<script type="text/javascript">
if($.url().param('ig') == 'true') {
alert("hi");
$('#icons').hide();
$('#photos').show();
end
</script>
Share
Improve this question
asked Jul 11, 2016 at 12:04
sachin godsachin god
6852 gold badges13 silver badges29 bronze badges
2
- which library is it? – hjpotter92 Commented Jul 11, 2016 at 12:05
-
Do you have such plugin included in page?
$.url
is not a jQuery core method – charlietfl Commented Jul 11, 2016 at 12:09
3 Answers
Reset to default 5$.url()
is not part of the jQuery Core. If you want to achieve something similiar, maybe use
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
to use it:
var tech = getUrlParameter('technology');
In your example it would something like this
if(getUrlParameter('ig') == 'true') {
source
//Just use this, no need to do loops:
var getUrlParameter = function getUrlParameter(sParam) {
var r = "";
if (window.locaton.href.substring(window.locaton.href.indexOf(sParam + "="))) {
r = window.locaton.href.substring(window.locaton.href.indexOf(sParam + "=")(sParam + "=").length + 1);
// trim if there is other parameter on the list
if (r.indexOf("&") > 0)
r = r.substring(0, r.indexOf("&"));
}
// please do some simple test, I just wrote it without testing the code
return r;
}
Your code might be assuming that the library purl library, https://github./allmarkedup/purl, is loaded but isn't or is inaccessible.
You might try the alternate approach:
if(purl().param('ig') == 'true') {