Reload iframe src / location with a new url that doesn't work in Safari

I have a page that loads with initially only the form inside the iframe, something like this:

<iframe id="oIframe" ...src='somePage>' <form ... /> </iframe>

When you click the button on the form, some javascript is called that builds the URL, and then I want to do the following:

frame.src = 'somePage?listId=1';

This works in IE to “reload” the frame with the new content. However, this does not work in Safari.

I have jQuery, but I do not want to replace the existing iframe, because there are events associated with it. I also cannot change the iframe id, because it is specified throughout the application.

I have seen some similar problems, but no solutions that seem to work well for my exact problem.

Any help anyone can provide would be great!

+7
source share
5 answers

I found a better solution (albeit not multiple eloquent) for this using jQuery.ajax:

 jQuery.ajax({ type: 'GET', url: "/somePage?someparms", success: function() { frameObj.src = "/somePage?someparms"; } }); 

This forces the DOM to be read inside the frame object and reloads it as soon as the server is ready to respond.

+3
source

Some browsers do not use "src" when invoking a javascript object directly from the javascript hierarchy, while others use "location" or "href" instead of "src" to change the URL. You should try these two methods to update your iframe with a new URL.

To prevent browser cache caching, add a pseudo-random string such as a number and a timestamp in the URL to prevent caching. For example, add “new Date (). GetTime ()” to your URL.

Some calling examples:

 document.getElementById(iframeId).src = url; 

or

 window.frames[iframeName].location = url; 

I recommend the first option using document.getElementById

You can also force the iframe to reload the page using

 document.getElementById(iframeId).reload(true); 
+5
source

So the answer is very simple:
1. put <div id="container"> </div> on your page
2. When a reboot is required, use the following jQuery:

 $("#container").empty(); $("#container").append("<iframe src='" + url + "' />"); 

and what is he. Of course, there is a more elegant way to create a DOM with jQuery, but this gives the idea of ​​a “refreshing” iframe. Works in FF18, CH24, IE9, O12 (well, this is jQuery, so it will work almost always :)

+4
source

try it

 form.setAttribute('src', 'somePage?listId=1'); 
0
source

Well, I was able to find what seems like a possible solution - this is work, but this is basically what I ended up with:

 var myFrame = document.getElementById('frame'); // get frame myFrame.src = url; // set src attribute of original frame var originalId = myFrame.id; // retain the original id of the frame var newFrameId = myFrame.id + new Date().getTime(); // create a new id var newFrame = "<iframe id=\"" + newFrameId + "\"/>"; // iframe string w/ new id myFrameParent = myFrame.parentElement; // find parent of original iframe myFrameParent.innerHTML = newFrame; // update innerHTML of parent document.getElementById(newFrameId).id = originalId; // change id back 
0
source

All Articles