0
我試圖保留事件數據時更換div與replaceWith()。當我嘗試它時找不到事件。目前我使用PostMessage的調用消息事件列表器來替換腳本潛水裏面的元素(用於在不被調用的消息事件)使用替換時保留事件數據使用替換
// Create IE + others compatible event handler
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
// Listen to message from child window
eventer(messageEvent,function(e) {
console.log('origin: ', e.origin);
// Check if origin is proper
if(e.origin != 'http://domain.com' || e.origin != 'http://www.domain.com'){ return }
console.log('revieced message: ', e.data);
player.Resume({ uuid: e.data.rid, title: e.data.rtitle });
var script = document.createElement('script');
script.text = "player.ready(function() { player.ima(adOptions);player.ima.requestAds(); window.SubtitlesOctopusOnLoad = function() { var options = { video: player.tech_.el_, subUrl: e.data.subtitleUrl || '<?php echo WEB_ROOT; ?>/files/<?php echo validation::safeOutputToScreen($file->subtitle); ?>', availableFonts: fonts, workerUrl: '<?php echo PLUGIN_WEB_ROOT; ?>/mediaplayer/assets/players/videojs/worker.js'};window.octopusInstance = new SubtitlesOctopus(options); window.octopusInstance.resize();}; if (SubtitlesOctopus) { SubtitlesOctopusOnLoad(); } });";
$('#subtitles').replaceWith(script);
}, false);
的script.text包含了我想要的數據保留 「e.data.subtitleUrl」
它在數據集中顯示爲undefined – Terrabyte
您的意思是'script.dataset.subtitleUrl'是'undefined'嗎? –
是它的顯示爲未定義 - 未捕獲TypeError:無法讀取未定義的屬性'數據' – Terrabyte