Follow us on Twitter!
Imagination is more valuable than knowledge - Albert Einstein
Friday, April 18, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 14
Guests Online: 14
Members Online: 0

Registered Members: 82822
Newest Member: TheBunter
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

For loop help, redirect loader

ShadowGate
Member

Your avatar

Posts: 24
Location:
Joined: 18.07.11
Rank:
Newbie
Posted on 05-07-12 02:08
I am working on a redirect script for a fancybox that loads a video, and then redirects the user to a new webpage when the fancybox is closed. I have the loader, and the redirect working.

However every video that is loaded redirects to the same page. I believe this to be a loop issue, and I could use some help.

Code
// Jquery to load fancybox with iframes, and redirects

var sponsors = [
    {selector: ".video_one", uri: "http://www.mysite.com"},
    {selector: ".video_two", uri: "http://www.anothersite.com"}
];

$(document).ready(function(){
    for(var i = 0; i < sponsors.length; i++) {
        var msg = sponsors[i].uri;
        var myDel = function(){window.location.replace(msg);}
        $(sponsors[i].selector).fancybox({
            'width' : '40%',
            'height' : '60%',
            'type' : 'iframe',
            'closeBtn': false,
            'afterClose': function(){myDel();}
        });
    }
});





Edited by ShadowGate on 05-07-12 04:29
Author

RE: For loop help, redirect loader

AldarHawk
Member



Posts: 1690
Location: Canada
Joined: 26.01.06
Rank:
Hacker Level 1
Posted on 05-07-12 12:23
utilizing a for statement here will not work because you are leaving the page after i=1 so the script in effect closes. You will need to set up an array and call through that.


Just ask Yahoo!Taboo! http://www.erikwestlake.com
Author

RE: For loop help, redirect loader

ShadowGate
Member

Your avatar

Posts: 24
Location:
Joined: 18.07.11
Rank:
Newbie
Posted on 06-07-12 18:52
Thank you for your reply. However I do not quite understand. I don't leave the page until the event is triggered by closing the fancybox on my site. Im trying to dynamically set up each event. Every video get loaded correctly. However each video only redirects to the last uri in my sponsors object.

I am going to try doing this with an array. I will post the code as soon as I am done. If you could explain the logic a little more I would greatly appreciated it.
Author

RE: For loop help, redirect loader

ShadowGate
Member

Your avatar

Posts: 24
Location:
Joined: 18.07.11
Rank:
Newbie
Posted on 07-07-12 10:02
Ok solved the problem. I had to enclose everything in the loop in a function. Weird to me but I guess its a javascript thing.

I found the answer here. sitepoint thread

Code
var mySponsors = [[".video_1", "http://www.site.com"], [".video_2", "http://www.anothersite.com"]];

$(document).ready(function(){
   for(i in mySponsors){
      (function(i){
         $(mySponsors[i][0]).fancybox({
            'width': '40%',
            'height': '60%',
            'type': 'iframe',
            'closeBtn': false,
            'afterClose': function(){window.location.replace(mySponsors[i][1]);}
         });
      })(i);
   }
});




Thanks for your help. Could still use a clarification as to why this works the way it does though.