0

i have onchage function on input <select> my code is working on parent page before, but how i can run my onchange function like this to effect the iframe

themeSelect.on('change', function(e) 
            {
                e.preventDefault();
                updateTheme(themeSelect.val());
});

i have tried this code

var $f = $("#myIFrame");
$f[0].contentWindow.updateTheme(themeSelect.val());

but it still does not work :(

i new on jquery, hope some one can help me please

2
  • Is the iframe src on the same domain as the parent page? If it is not, then you can't do this as long as you don't have acess to edit the source code of that iframe content. Commented Apr 15, 2016 at 9:22
  • if you have both the iframe and the parent page under same domain you can have control over the iframe DOM else not.. Commented Apr 15, 2016 at 9:23

1 Answer 1

1

you can do this like these way,

code is for asp.net but will help you to get parent data.

There are multiple ways to do these.

I) Get main parent directly.

top.location.replace(link);

here top.location gets parent directly.

II) get parent one by one,

var element = $('.iframe:visible', window.parent.document);

here if you have more then one iframe, then specify active or visible one.

you also can do like these for getting further parents,

var masterParent = element.parent().parent().parent()

III) get parent by Identifier.

var myWindow = window.top.$("#Identifier")
Sign up to request clarification or add additional context in comments.

3 Comments

where i should put the script ? my iframe src on parent folder like this : <iframe id="getIframe" src="localhost/design/bootstrap-3.3.6" style="width: 100%; height: 100%;" scrolling="yes" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0"> Sorry, your browser don't support Iframe </iframe>
i use iframe because my jquery and style are conflict
ok, denis do one thing, put all your code to jsFiddle, and give me it's link, so that i can debugg and give you proper answer..

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.