How do I stop executing a function from an iFrame

I have one iFrame in my index.html file, onload of iFrame there is one function executing. I want to stop that function from my index.html . How Can I do that? because I can’t edit test.html functions, I need to control from my index.html. Both files are in the same server.

Hi sdrebel welcome to the forum

I think the easiest way would be to edit the iframed page to test for “window.parent” eg.

If it is in the iframe, have the code return without running.

Thank You. How do I use window.parent here. Ex: Now test.html is there and function fnTest() is getting executed onLoad of test.html. But when I call that test.html through iFrame it shouldn’t execute. Should I use window.parent.fnTest() ? I tried with $.Callbacks(), but problem is both will run.

Can you post the function?

function fnTest(id) {

This is just a example. basically that function tracks the Id of the slide. and that track function is from a particular platform. So when I run test.html in that platform fnTest() should run else it shouldn’t execute.

Try this, testing both ways, not in an iframe and in an iframe. .

function fnTest(id) {
  if (window.parent != {
    console.log("we've been framed I tell ya");

If that doesn’t work, please post the actual function instead of an example.


I tried this code but it’s not executing. I can’t change function in the test.html. Whatever I have to do I should do it in index.html

Have you tried the sandbox attribute, that prevents scripting within the iframe?

Scripting within an iframe is either an all or nothing situation.

Ya but that stops all the script functions. There are multiple scripts and functions running. I want stop only one function not all.

For security reasons, you’re not allowed that much control over the contents of the iframe.

Even When files are in the same server?

My actual function
function fnTest(arg1){
… Some code …
Since com.veeva.clm.createRecord(“Call_Clickstream_vod__c”,clickStream,saveData); is coming from platform Library, I don’t want fnTest() to execute from Index.html.

Can we do something with document.getElementById(“ifrm”).contentWindow.fnTest(1) ?

When on the same server you can run functions inside of the iframe, but to the best of my knowledge you cannot stop existing code from being run.

So there is no solution? Can we disable a particular script file?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.