views:

99

answers:

2

This used to work, but for some reason it doesn't anymore. I use a javascript to change the source of an iframe and then refresh it. The reason is I want to send a variable into the iframe before it is viewed.

I added som debug code, and it shows "debug 1" but not "debug 2".

What might be the issue?

$("#upload_iframe").attr("src", "/editor/upload/?dir=" + dir);
// ---------------------------------
// THESE LINES DON'T WORK - STOPS AFTER FIRST DEBUG IS RUN...
// ---------------------------------
alert('debug 1');
$("#upload_iframe").contentWindow.location.reload(true);
alert('debug 2');
// ---------------------------------
$("#upload_file").dialog('open');
+2  A: 

Personally, I've not had much luck using the "reload()" method. Try this:

$("#upload_iframe").contentWindow.location.href = $("#upload_iframe").contentWindow.location.href;
Joe D
+3  A: 

As you want to access the dom and not the jquery object you should add [0] :

$("#upload_iframe")     //is an array of matching dom objects
$("#upload_iframe")[0]  //is the first matching dom object

You might also add a random string to prevent browser caching:

$("#upload_iframe")[0].contentWindow.location.href = "/editor/upload/?dir=" + dir + "&rid=" + Math.random();
Ghommey
Thank you, that solved it.
Christoffer