Skip to content

Commit

Permalink
IE fix: calling matchMedia with an empty string (prebid#4691)
Browse files Browse the repository at this point in the history
* IE fix for matchMedia

matchMedia throws an error if it gets an empty string as parameter on IE

* Removed trailing space
  • Loading branch information
benjaminclot authored and hellsingblack committed Mar 5, 2020
1 parent 4e14677 commit 042f631
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/sizeMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,16 @@ function evaluateSizeConfig(configs) {
) {
let ruleMatch = false;

try {
ruleMatch = getWindowTop().matchMedia(config.mediaQuery).matches;
} catch (e) {
logWarn('Unfriendly iFrame blocks sizeConfig from being correctly evaluated');

ruleMatch = matchMedia(config.mediaQuery).matches;
if (config.mediaQuery === '') {
ruleMatch = true;
} else {
try {
ruleMatch = getWindowTop().matchMedia(config.mediaQuery).matches;
} catch (e) {
logWarn('Unfriendly iFrame blocks sizeConfig from being correctly evaluated');

ruleMatch = matchMedia(config.mediaQuery).matches;
}
}

if (ruleMatch) {
Expand Down

0 comments on commit 042f631

Please sign in to comment.