Refreshing an iFrame from a client script??? or anywhere???

theiser
Tera Expert

First of all, I am doing this in order to create a filter on the service catalog.

I am looking for code that will refresh specific/all iFrames. Here is the problem.I have an iFrame on the left that contains a specific view of the user profile. I have been able to add a client script that will automatically save/update the profile if a box is checked.   I then have a BR that adds that user to the group that was checked. I now need code that will update the iFrame on the right side.

Refresh iFrame.tiff

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

It sounds like you're inside of one iframe and trying to change the src on a different iframe. In this case when you call document, it's limited to the elements in your left iframe. In order to get around this, you should be able to use top to start at the top level document.



Try:


top.document.getElementById('gsft_main_az').src = top.document.getElementById('gsft_main_az').src




You could also do something like this:



top.document.getElementById('gsft_main_az').contentWindow.location.reload(true);

View solution in original post

11 REPLIES 11

justin_drysdale
Mega Guru

Give your iframe an id if it doesn't already have one, then:




document.getElementById('iframe_id').src += '';

Receiving this error. I have renamed the iframe to "gift_main_az".




onChange script error: TypeError: 'null' is not an object (evaluating 'document.getElementById('gsft_main_az').src') function onChange_sys_user_u_international_10(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue == '') return; document.getElementById('gsft_main_az').src += ''; }


Try this:-



document.getElementById('iframeid').src = document.getElementById('iframeid').src



Thanks & regards,


Hari


Still getting an error. I have added my client script. It is based on the sys_user   table, Since that is the table with the checkboxes. Again, based on the image above, when a checkbox is checked I use the below client script to call a UI action to automatically save the sys_user table. I then need to be able to see the I-frame next to it.



Error MessageonChange script error: TypeError: 'null' is not an object (evaluating 'document.getElementById('gsft_main_az').src') function onChange_sys_user_u_international_10(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue == '') return; document.getElementById('gsft_main_az').src = document.getElementById('gsft_main_az').src; }


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue == '')


  return;


  gsftSubmit(null, g_form.getFormElement(), 'Filter_sysverb_update_and_stay');


  document.getElementById('gsft_main_az').src = document.getElementById('gsft_main_az').src


}