简体   繁体   中英

javascript in iframe to access and modify select element of parent

I have this line of code that works fine for me:

$("#select_mod_completed_project option[value='" + projectname + "']").remove();

it basically just removes one of the options from my select box. The option to be removed is defined in the 'projectname' js var. Now this works fine for me when running in a single window but I need to to run from an iframe and the select box will be in the parent of that iframe.

In the parent document, set a function that executes this code:

function removeOption(projectname) {
  $("#select_mod_completed_project option[value='" + projectname + "']").remove();
}

Then just call it from the iframe using window.parent :

parent.removeOption('test');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM