Skip to content

Commit

Permalink
fix: iframe onload event before inject iframe
Browse files Browse the repository at this point in the history
on fiirefox bug if there are image with 404 status because iframe is not yet ready
  • Loading branch information
wonknu committed Nov 3, 2016
1 parent 362729f commit 4c6624a
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/server/public/scripts/modules/EditorReload.js
Expand Up @@ -54,24 +54,26 @@ export default class Reload {

inject(str) {
var iframe = document.querySelector('#page-template')
var iframeBody = IframeDocument('#page-template').body
var scrollTop = iframeBody.scrollTop

var doc = iframe.contentWindow.document
str = str.replace(/<\/head>/, '<base href="/" /></head>')
var template = Handlebars.compile(str, {noEscape: true})
str = template(json)
doc.open()
doc.write(str)
doc.close()
iframe.onload = function() {
var iframeBody = IframeDocument('#page-template').body
var scrollTop = iframeBody.scrollTop

setTimeout(function () {
var iframeDoc = IframeDocument('#page-template')
if(typeof iframeDoc !== 'undefined' && iframeDoc !== null
&& typeof iframeDoc.body !== 'undefined' && iframeDoc.body !== null) {
iframeDoc.body.scrollTop = scrollTop
}
}, 1000)
var doc = iframe.contentWindow.document
str = str.replace(/<\/head>/, '<base href="/" /></head>')
var template = Handlebars.compile(str, {noEscape: true})
str = template(json)
doc.open()
doc.write(str)
doc.close()

setTimeout(function () {
var iframeDoc = IframeDocument('#page-template')
if(typeof iframeDoc !== 'undefined' && iframeDoc !== null
&& typeof iframeDoc.body !== 'undefined' && iframeDoc.body !== null) {
iframeDoc.body.scrollTop = scrollTop
}
}, 1000)
}
}

reload() {
Expand Down

0 comments on commit 4c6624a

Please sign in to comment.