ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to modify blankwin.js script?

May 16, 2008 12:51pm

Subscribe [2]
  • #1 / May 16, 2008 12:51pm

    Mark Bowen

    12637 posts

    Hi there,

    Just wondering if any Javascript gurus out there could possibly help me to figure something out?

    I am using the great little blankwin.js script on a site and it works fine.

    I have one slight need though. I would like to be able to not have it affect certain external links so I was thinking that perhaps I could place a certain class name on those links say something like css=“my-class disregard-blankwin” and then I can check for the disregard-blankwin part and if it exists on any links don’t apply the blankwin.js script

    I did have a go by placing this :

    /* SOF - My Code */
    for(i=0;i<a.length;i++){
    // Check for the right classname
    if(a<i>.className != "disregard-blankwin"){
    /* EOF - My Code */

    into the blankwin.js script just after the :

    var a = document.getElementsByTagName("a");

    part and hoped that any links with that class name would get overlooked but it still just operated in the same way that it did originally. Just to mention that I did put in the two closing } brackets after the rest of the blankwin.js code so the javascript was all valid but it still seems to just get all the a links and apply the script regardless of the if className part that I have put in!

    If anyone has any idea of what I am bufooning on about and can lend a hand then I would be most appreciative. My Javascript really isn’t that good and I find it quite difficult to get my head around at the moment what with everything else going on inside my noggin so thanks for any help on this. I did try though honest as can be seen from the code I tried to inject into the existing javascript 😉 😊 😉

    Thanks in advance for any help on this one.

    Best wishes,

    Mark

  • #2 / May 16, 2008 1:55pm

    asozzi

    262 posts

    If I understood you correctly you inserted a second loop into the program? If so you had the right idea at the wrong place try this:

    ...
    for (var i=0;i<a.length;i++){
        if(a<i>.className!="disregardBlankwin"){
            if(check(a<i>)) set(a<i>);
        };
    };
    ...

    You see all the other parts of the program don’t get called except for the if(check…) loop, so you have to wrap your additional disregard filter around that, also I’m not too sure about using hyphens in class names (i.e disregard-Blankwin).

    EDIT: I hope it is clear that this is supposed to go on line 14 in the original script.

  • #3 / May 16, 2008 3:36pm

    Mark Bowen

    12637 posts

    Hiya,

    Thanks for the reply. I did try placing your code into the original code. Not too sure that it is line 14 though? More like line 22 maybe?

    Did place it so that it looks the same as yours though but it still doesn’t work unfortunately. I have attached my script with the changes to this post - maybe you could possibly take a look and let me know where I have gone wrong?

    Thanks again for the help on this.

    Best wishes,

    Mark

  • #4 / May 16, 2008 3:52pm

    asozzi

    262 posts

    I’ll have a look a bit later… but if you have jquery already loaded this would do the same thing:

    $('a[href^=http]:not(.disregardBlankwin)').not('[href*=yourdomain.com]').addClass('external');

    just as an afterthought, you did add the class disregardBlankwin to some links?

  • #5 / May 16, 2008 4:14pm

    Mark Bowen

    12637 posts

    Hiya,

    Thanks for that code will try that out instead now. Yep I did add in the new class name to the links as well though 😉

    Thanks again. If you wouldn’t mind looking later on as I would love to understand all of this and learning from getting the blankwin.js script working (well you would be doing that really - getting it working I mean 😉 ) would be a good way to start for me.

    Thanks again.

    Best wishes,

    Mark

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases