rewdy / leaveNotice

A jQuery plugin for notifying users of their exiting a page.
http://rewdy.com/tools/leavenotice-jquery-plugin
17 stars 9 forks source link

Not working on my site, can you give me a hand for a sec? #3

Closed asscore closed 11 years ago

asscore commented 11 years ago

Hello, I'm not very well versed in Javascript, but I thought I had this installed properly but it is not working.

The site is salt101.com

Here is the code I tried using...

Any help or pointers would be much appreciated!

asscore commented 11 years ago

BTW I am not calling the css file because I just dumped all the code in my main template css file.

rewdy commented 11 years ago

Yeah, I can help.

The code you are using to initiate leaveNotice looks for links with the attribute rel="external". This is suggested because it's somewhat more standards-compliant, however, it's not often the most convenient way to do it. In order to make that code work, you'd have to put rel="external" on all your external links. (Not probably something you want to do.)

I took a look at your site and it seems that you internal sites links are all relative (i.e. they links to "/something" as opposed to "http://www.salt101.com/whatever".) Since this is the case, you can initiate the plug in so it applies the behavior to all links that start with "http://", thus targeting the external links. Here's how you would do it:

$(function(){
    $('a[href^="http"]').leaveNotice({siteName: 'Salt101'});
});

Let me know if that works for you. Good luck! :)

asscore commented 11 years ago

Hi, thanks for taking the time to give me a hand.
Unfortunately your code isnt working for me, also I even tried adding rel="external" to my link as well and that isn't working either.

Right now I put the script right before the end of in my CMS templates index file with all my other scripts. Is this the best place for this? I'm sure your script works fine I am just screwing this up somehow.

rewdy commented 11 years ago

I'm not totally sure. Right now, it appears you have two closing });s that is throwing an error. You can remove one of those.

Other things to try:

You can omit including the jQuery library before you include the leaveNotice script. This is because I can see that your site is already calling in jQuery. There's no need to call it in twice. That could help.

The other thing is that since you're also using Mootools (at least the script is being called in), you can try replacing the dollar sign with 'jQuery'. Sometimes that creates problems.

So, you'd have:

jQuery(function(){
    jQuery(...same as before...);
});

See if that gets your anywhere...

rewdy commented 11 years ago

I'm closing this ticket from lack of activity. If you continue to have trouble, you can let me know andrew [at] rewdy [dot] com