I have a function called Designer and I want to return this function if location.hash equals isDesign. I tried the following...
function Designer() {
$("#boxA").fadeIn(700);
$("#boxA span#closeControl").on("click",function(){
$("#builderBox").fadeOut(700);
});
}
if (location.hash = "isDesign") {
return Designer();
}
Instead of the function executing, it assigns the isDesign hash to the url and reloads the page several times. Please, what should I do to correct this. All answers will be appreciated. Thank you.
I have a function called Designer and I want to return this function if location.hash equals isDesign. I tried the following...
function Designer() {
$("#boxA").fadeIn(700);
$("#boxA span#closeControl").on("click",function(){
$("#builderBox").fadeOut(700);
});
}
if (location.hash = "isDesign") {
return Designer();
}
Instead of the function executing, it assigns the isDesign hash to the url and reloads the page several times. Please, what should I do to correct this. All answers will be appreciated. Thank you.
Share Improve this question edited Dec 13, 2013 at 12:41 Delali asked Dec 13, 2013 at 12:40 DelaliDelali 9082 gold badges16 silver badges24 bronze badges 4- The Designer-function does not return anything, do you simply want to call it if the hash matches? Also the hash, I believe, would be "#isDesign" would it not? – Esko Commented Dec 13, 2013 at 12:43
- Yes, but it is still not working. I tried to call an alert instead of returning the function but it did not work. – Delali Commented Dec 13, 2013 at 12:48
-
if (location.hash = "isDesign")
You're missing (at least) an = on this line. A single = is assigning a value to location.hash. Since you're paring values, you need == (or === for strict typing). – fastasleep Commented Mar 14, 2014 at 7:53 -
The unsolved problem here is how to deal with URLencoding; e.g.
if (location.hash == '#'+id)
isn't quite right if e.g.id == "HQ9+"
, because you'll find thatlocation.hash == "#HQ9%2B"
instead. – Quuxplusone Commented Nov 12, 2023 at 21:46
2 Answers
Reset to default 5Try this:
$(function() {
if (location.hash === "#isDesign") {
Designer();
}
});
function Designer() {
$("#boxA").fadeIn(700);
$("#boxA span#closeControl").on("click",function(){
$("#builderBox").fadeOut(700);
});
}
or just
$(function() {
if (location.hash === "#isDesign") {
$("#boxA").fadeIn(700);
$("#boxA span#closeControl").on("click",function(){
$("#builderBox").fadeOut(700);
});
}
});
Use
if (location.hash == "isDesign") {
return Designer();
}
Single =
is assignment, double ==
is parison