Adding Javascript Quick Page Escape

Greetings,

I’m have a difficult time trying to add a bit of Javascript. I am trying to call (with an image or button) a script that allows the user to ‘escape’ from a page quickly. It works on my present HTML site, and am developing a new site using X-Theme child- theme. Please help, as I’ve tried a number of things, and don’t know enough about what I’m trying to do to make it work.

The presently working site is http://crisis-support.org/site/index.html (I am developing the WP site on the root and re-directing the live site to the folder “site”.

Hi There,

Unfortunately, I can’t access your login page using the normal /wp-admin or wp-login.php. It says page not found. Did you change the login URL? Please provide it.

Although, upon checking, I can see a JS error. Please update the code to this:

function getAway() {
 // Get away right now
window.open("http://facebook.com", "_blank");
// Replace current site with another benign site
window.location.replace('http://google.com');
}

jQuery(function($) {

  $("#get-away").on("click", function(e) {
    getAway();
  });

  $("#get-away a").on("click", function(e) {
  // allow the (?) link to work
  e.stopPropagation();
  });

  $(document).keyup(function(e) {
  if (e.keyCode == 27) { // escape key
    getAway();
   }
 });

});

Hope this helps.

Hi Lely,

Weird on the access thing. I’m having no trouble logging in the regular way - www.crisis-support.org/wp-admin … but there might be something with the temporary re-direct I have set up. Anyway, your JS fix worked. Thanks a bunch!

Is there a way to call external js scripts? If so, how can I do that? I have a few others I would rather keep external if possible.

Oy, sorry to keep adding to this … The original fix worked perfect in Safari and Chrome, but not in Firefox. I haven’t tried IE yet. Any idea how to make it Firefox-friendly?

Hi There,

You’re always welcome!

For external javascripts:
1] Copy all the Javascript files into the child theme’s folder: x-child/js/

2] Add following PHP code into the functions.php file locates in the child theme’s folder:
function x_add_scripts(){ wp_enqueue_script( 'x-script-1', get_stylesheet_directory_uri() . '/js/script-1.js', array('jquery') ); } add_action( 'wp_enqueue_scripts', 'x_add_scripts' );

Then replace the script-1.js by your javascript’s file name.

Try to clear browser cache. It is working on Firefox when I checked. See this: https://screencast-o-matic.com/watch/cbifDulI5H

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.