Welcome Guest, Not a member yet? Register   Sign In
Using jQuery modal pop up as a leaving the site page?
#1

[eluser]gwerner[/eluser]
I'm trying to implement a jQuery pop up modal that catches links that will send a user away from my site. The jQuery catches any link with a class of "depart". I'm using .get to grab the appropriate controller that will then grab the default view and load that into the modal. I think what is happening is since I'm passing URLs as a segment variable, Codeigniter is trying to use the segments created in the passed URL? Which in turn is resulting in 404 errors. Which is where I'm stuck.

Any help is appreciated. Even if there is better way to handle this all together.

Sample Link
Code:
<a class="depart" href="http://www.newsite.com/you/are/now/leaving/example.html?v=1">A link that will exit the site.</a>

The above would output to Codeigniter using the jQuery .get below:
/depart/http://www.newsite.com/you/are/now/leaving/example.html?v=1


Jquery
Code:
jQuery(function ($) {
var OSX = {
  container: null,
  init: function () {
   $('.depart').click(function (e) {
    e.preventDefault();
    var myid = $(this).attr('href');
    $.get("/depart/" + encodeURIComponent(myid), function(data){
     $(data).modal({
      opacity: 65,
      overlayClose: true,
      onOpen: OSX.open
     });
    });
   });
  },
  open: function (d) {
   var self = this;
   self.container = d.container[0];
   d.overlay.fadeIn('slow', function () {
    $("#depart", self.container).show();
    d.container.fadeIn('slow', function () {
     d.data.fadeIn('slow');
    });
   });
  }
};
OSX.init();
});
#2

[eluser]gwerner[/eluser]
So, this is what I came up with that seems to work. I updated the jQuery .get to include a url= parameter. Then let Codeigniter get that variable in the controller. If the variable is set and the link exists in the database the user may then proceed exiting the site by clicking the link.

jQuery
Code:
$.get("/depart/?url=" + encodeURIComponent(myid), function(data){

Controller index method
Code:
$url = $this-&gt;input-&gt;get('url');
  $this-&gt;data['continue'] = isset($url]) && $this-&gt;links_model-&gt;check_link($url) == TRUE ? '&lt;a href="'.$url.'">Continue</a>' : '<a href="">Continue</a>';




Theme © iAndrew 2016 - Forum software by © MyBB