diff --git a/lib/editor/htmlarea/htmlarea.php b/lib/editor/htmlarea/htmlarea.php
index fee6d10..3bacf2e 100644
--- a/lib/editor/htmlarea/htmlarea.php
+++ b/lib/editor/htmlarea/htmlarea.php
@@ -32,11 +32,13 @@
     if ($httpsrequired) {
         // this is an ugly hack to allow partial operation of editor on pages that require https when loginhttps enabled
         // please note that some popups still show nonsecurre items and fullscreen may not function properly in IE
-        $url = preg_replace('|https?://[^/]+|', '', $CFG->wwwroot).'/lib/editor/htmlarea/';
+        $wwwroot = preg_replace('|https?://[^/]+|', '', $CFG->wwwroot);
     } else {
-        $url = $CFG->wwwroot.'/lib/editor/htmlarea/';
+        $wwwroot = $CFG->wwwroot;
     }
 
+    $url = $wwwroot.'/lib/editor/htmlarea/';
+
     $strheading = get_string("heading", "editor");
     $strnormal = get_string("normal", "editor");
     $straddress = get_string("address", "editor");
@@ -721,7 +723,7 @@ HTMLArea.prototype.generate = function () {
     // create the IFRAME
     var iframe = document.createElement("iframe");
 
-    iframe.src = "<?php echo $CFG->wwwroot ?>/lib/editor/htmlarea/blank.html";
+    iframe.src = "<?php echo $wwwroot; ?>/lib/editor/htmlarea/blank.html";
 
     iframe.className = "iframe";
 
