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

Can you tell me what is the requirement exactly? Is it a custom iFrame or something OOB?



Thanks & Regards,


Hari


here are the steps/actions I need to be accomplished:


  1. check a field (International) in the sys_user table
  2. automatically save the sys_user table
    • this works using   gsftSubmit(null, g_form.getFormElement(), 'Filter_sysverb_update_and_stay');
  3. run a BR that looks for the check in the international field of the sys_user table that will add the user to a group called "international".
    • this group will be used to filter service catalog items by using the ' available for group' field
    • this works as well
  4. refresh/reload the I-frame next to it — having issues doing this, all suggestions so far provides an error that null is not in object
    • I need to refresh to occur in order to remove/add service catalog items based on the group.



The I-frame contains a query to service catalog items


Screen Shot 2014-07-17 at 9.32.42 AM.png


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);

Updated.



Your 2nd script does work.


My first look was clicking   a check box in the backend, directly in the sys_user table. It gives an error since there is no iframe. However, on the portal it works correctly.



Thank you.


Brad, When i try to apply the code to add scroll-bar in IE9 it does not work , where as it is working for Mozilla.