0

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');
1
  • i do not think reload needs an argument. Try to remove one. Commented Aug 28, 2009 at 13:11

2 Answers 2

4

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();
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You! Adding the Math.random() to my querystring fixed a day's worth of headache.
2

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

$("#upload_iframe").contentWindow.location.href = $("#upload_iframe").contentWindow.location.href;

Comments

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.