1

I have this code to fix the issue of flash hopping over all your content in the z-index:

$("iframe").each(function(){
    var ifr_source = $(this).attr('src');
    var wmode = "wmode=opaque";
    if(ifr_source.indexOf('?') != -1) {
        var getQString = ifr_source.split('?');
        var oldString = getQString[1];
        var newString = getQString[0];
        $(this).attr('src',newString+'?'+wmode+'&'+oldString);
    }
    else $(this).attr('src',ifr_source+'?'+wmode);
});

For some reason, i'm getting errors on the indexOf, and it's breaking the site. But oddly, it's not breaking it entirely, just one css resize fix I have on there.

Uncaught TypeError: Cannot call method 'indexOf' of undefined

The site is here: http://syndex.me

Would love to know why this is happening.

2 Answers 2

2

Get the src directly from this. You do not need to create a whole jQuery object for this.

ifr_source = this.src;

As a bonus, this.src returns an empty string even if the attribute src is not set, whereas jQuery's attr returns undefined and you have to perform a check before using indexOf.

Sign up to request clarification or add additional context in comments.

Comments

1

Probably you have iframe without any src attribute declared at all.

Have this to avoid the error:

var ifr_source = $(this).attr('src') || "";

Edit: viewing the source here it is indeed:

<iframe id="likeit"></iframe>

On second thought, adding to the URL of this frame won't be good idea, better just leave it alone, so final code should be:

var ifr_source = $(this).attr('src') || "";
if (ifr_source.length > 0) {
    var wmode = "wmode=opaque";
    if(ifr_source.indexOf('?') != -1) {
        var getQString = ifr_source.split('?');
        var oldString = getQString[1];
        var newString = getQString[0];
        $(this).attr('src',newString+'?'+wmode+'&'+oldString);
    }
    else
        $(this).attr('src',ifr_source+'?'+wmode);
}

4 Comments

It's weird though cos then the desired effect, adding ?wmode=opaque does not happen. It does stop the error though.
If you'll add it, you will cause infinite loop as the iframe will refer to the same page.
Sorry I don't understand, my goal is to check if an iframe src has a question mark in it, if it does, i can attach a parameter to that string (which will stop the z-index issue of the youtube flash video. I dont understand why after your checks proposed in the new code, that it would cause an inifinte loop, isnt that going against the point of the code? Thanks for your time and patience.
My whole point is to ignore iframe with no source - it should work just fine (like before) with frames pointing somewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.