Links in courseware iframed in MFEs navigate parent window (#22962)

[TNL-7043] If vertical block content is in an iframe in the learning microfrontend app, add a base tag in the head (of the iframe document) to force links to navigate the parent window.
This commit is contained in:
Adam Butterworth
2020-01-28 15:49:54 -05:00
committed by GitHub
parent f46458fbfe
commit 2968401e09
4 changed files with 19 additions and 0 deletions

View File

@@ -3755,6 +3755,7 @@ PROFILE_MICROFRONTEND_URL = None
ORDER_HISTORY_MICROFRONTEND_URL = None
ACCOUNT_MICROFRONTEND_URL = None
PROGRAM_MANAGER_MICROFRONTEND_URL = None
LEARNING_MICROFRONTEND_URL = None
############### Settings for the ace_common plugin #################
ACE_ENABLED_CHANNELS = ['django_email']

View File

@@ -293,3 +293,6 @@ SECRET_KEY = '85920908f28904ed733fe576320db18cabd7b6cd'
EDXNOTES_INTERNAL_API = 'http://edx.devstack.edxnotesapi:18120/api/v1'
EDXNOTES_CLIENT_NAME = 'edx_notes_api-backend-service'
############## Settings for Microfrontends #########################
LEARNING_MICROFRONTEND_URL = 'http://localhost:2000/'

View File

@@ -1133,6 +1133,7 @@ WRITABLE_GRADEBOOK_URL = ENV_TOKENS.get('WRITABLE_GRADEBOOK_URL', WRITABLE_GRADE
PROFILE_MICROFRONTEND_URL = ENV_TOKENS.get('PROFILE_MICROFRONTEND_URL', PROFILE_MICROFRONTEND_URL)
ORDER_HISTORY_MICROFRONTEND_URL = ENV_TOKENS.get('ORDER_HISTORY_MICROFRONTEND_URL', ORDER_HISTORY_MICROFRONTEND_URL)
ACCOUNT_MICROFRONTEND_URL = ENV_TOKENS.get('ACCOUNT_MICROFRONTEND_URL', ACCOUNT_MICROFRONTEND_URL)
LEARNING_MICROFRONTEND_URL = ENV_TOKENS.get('LEARNING_MICROFRONTEND_URL', LEARNING_MICROFRONTEND_URL)
############### Settings for edx-rbac ###############
SYSTEM_WIDE_ROLE_CLASSES = ENV_TOKENS.get('SYSTEM_WIDE_ROLE_CLASSES') or SYSTEM_WIDE_ROLE_CLASSES

View File

@@ -45,6 +45,20 @@ ${static.get_page_title_breadcrumbs(course_name())}
<link href="${static.url('css/vendor/jquery.autocomplete.css')}" rel="stylesheet" type="text/css">
${HTML(fragment.head_html())}
<script type="text/javascript">
// If this chromeless view is in an iframe in the learning microfrontend app
// then add a base tag in the head (of the iframe document) to force links
// in this iframe to navigate the parent window.
if (window !== window.parent) {
var learningAppReferrer = "${settings.LEARNING_MICROFRONTEND_URL | n, js_escaped_string}";
if (document.referrer === learningAppReferrer) {
var baseElement = document.createElement('base');
baseElement.setAttribute('target', '_parent');
document.head.appendChild(baseElement);
}
}
</script>
</%block>
<%block name="js_extra">