Nested “proxy” iframe (myLMS.com)
When the content iframe creates the nested proxy frame, it appends a querystring. The proxy frame therefore needs to examine the proxy’s window.location parameter for a querystring, then act on the value of the querystring.
window.onload = function (){ var result, pairs; var querystring = window.location.href.split("?")[1] || false; //Ensure querystring exists and has valid result identifier if(!querystring || querystring.indexOf("result=") === -1){ return false; } //Ensure all ampersands are single (not entities) so we can split using "&" querystring = querystring.replace(/&/g, "&"); //Create an array of value pairs. This gives us flexibility //to add more items to the querystring later. pairs = querystring.split("&"); //Loop through the pairs and act on each one. for(var i = 0; i < pairs.length; i++){ //We're currently only looking for the 'result' value //We can add more if needed by adding more 'if' and 'switch' statements //Find 'result' variable if(pairs[i].indexOf("result=")){ //Extract the value from the string by replacing the //identifier/assignment portion of the string with nothing "" result = pairs[i].replace("result=", ""); } } //Only act on valid values. //DO NOT try to use eval() here. Big no-no. switch(result){ //Must specify "top." before the function invocation so that //the browser knows to send the JS to the topmost parent frame case "passed" : top.interactionCompleted("passed"); break; case "failed" : top.interactionCompleted("failed"); break; } };
If you remove the comments and extra line breaks, this is a very short script that weighs in at 16 lines. Also, as I mentioned in the comments, please don’t try to use eval() on the querystring; it would be very unwise and would cause major security vulnerabilities, much like an SQL injection.