-
AuthorPosts
-
July 7, 2021 at 9:50 pm #1309162
Hello you smart cookies :)
I am working on a Victim Services page that required to have a “Quick Exit / ESCAPE” that redirects and got that to work perfectly BUT now the dropdowns in the navigation have vanished. I know that it is due to the extra scripts can you please help me maybe combine the scripts so I can have the best of an escape button and a fully functioning dropdown navigation lol
I know it is the scripts since all worked just fine and returned when I removed them. :/
Thanks SO very much in advance!
~MDM TeamJuly 11, 2021 at 9:19 pm #1309610Hey amanda-mdllc,
Thank you for your patience, I tested your script in a code block on a test site and I added a custom ID to a special heading element to test the$("#get-away").on("click", function(e) { e.stopPropagation(); getAway(); });
I also added a text link with the ID
#get-away
to test the$("#get-away a").on("click", function(e) { e.stopPropagation(); getAway(); });
So while my menu sub-menu was working I found it was shifted to the left a ways, the reason was your first line in the script was calling
src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
, jQuery v1.7.2, where the theme includes v3.5.1 once I removed this old version the script seemed to run ok.
But my research pointed toreturn false;
working better thane.stopPropagation();
, and the text link didn’t work because it needed to be$("a#get-away").on("click", function(e)
and I don’t see why you are adding$("#get-away-mobile").on("click", function(e)
when$("#get-away").on("click", function(e)
would also work, but I left that. I then tested why the(e.keyCode == 27)
only triggers thewindow.location.replace
and notwindow.open
and I could not find out why the key press won’t work, but I did find thatwindow.open
reportedly doesn’t work with Safari, so for this you will have to be happy with at leastwindow.location.replace
working.
Anyways I rewrote it a little as a function you can add to your child theme functions.php file:function custom_getaway_script() { ?> <script> (function($){ function getAway() { // Get away right now window.open("http://weather.com", "_newtab"); // Replace current site with another benign site window.location.replace('http://google.com'); } function getAwayMobile() { // Get away right now window.open("http://weather.com", "_newtab"); // Replace current site with another benign site window.location.replace('http://google.com'); } $("#get-away").on("click", function(e) { getAway(); return false; }); $("a#get-away").on("click", function(e) { getAway(); return false; }); $(document).keyup(function(e) { if (e.keyCode == 27) { getAway(); } }); $("#get-away-mobile").on("click", function(e) { getAwayMobile(); return false; }); $("a#get-away-mobile").on("click", function(e) { getAwayMobile(); return false; }); })(jQuery); </script> <?php } add_action('wp_footer', 'custom_getaway_script');
Hopefully this helps.
Best regards,
MikeJuly 12, 2021 at 10:01 pm #1309856Hey there Mike!
Thanks so much for getting that over to me. I am literally putting the website live today so I will give this script a test tomorrow and get back to you.
Thanks so much in advance!
~MDM TeamJuly 13, 2021 at 11:03 am #1309911 -
AuthorPosts
- You must be logged in to reply to this topic.