javascript - Loading Highcharts in an iframe -


i'm trying load chart (using highcharts) in iframe, load highcharts console returns $(...).highcharts not function

$('<iframe id="panel_frame_container" frameborder="0"/>').load(function(){             $('#panel_frame_container').contents().find('body').append("<div id='panel_chart_container'></div>").end()                                                   .find('body').append('<script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"><\/script>').end()                                                   .find('body').append('<script src="https://code.highcharts.com/highcharts.js"><\/script>').end()                                                   .find('body').append('<script src="https://code.highcharts.com/highcharts-more.js"><\/script>').end()                                                   .find('body').append('<script src="https://code.highcharts.com/modules/exporting.js"><\/script>').end()                                                   .find('body').append("<script type='text/javascript'>$(document).ready(function(){console.log('loaded');$('#panel_chart_container').highcharts("+data2+");});<\/script>");         }).appendto($(".panel-body")); 

https://jsfiddle.net/s82v657e/

my goal let user set own datas (data2) choose iframe lock him out of main window since can use functions in highcharts, i'll add sandbox tag in iframe when first part work.

i think should not inject yours scripts javascript that. instead create dynamic page iframe.php content easier.

iframes have restricted rights , way load yours scripts doesn't guarantee done 1 after another

quick example iframe.php content, pass data_id inside iframe url:

<?php  if (isset($_get['data_id'])) $data = getgraphics( $_get['data_id']); ?> <html> <head> </head> <body> <div id="panel_chart_container"></div> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/highcharts-more.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <script type='text/javascript'> $(document).ready(function(){ $('#panel_chart_container').highcharts(<?=$data;?>); }); </script> </body> </html> 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

post - imageshack API cURL -

dataset - MPAndroidchart returning no chart Data available -