问题
Related.. (HTML, JAVASCRIPT, Iframe)
I add code into Iframe's element using javascript(Dynamically.).
After I set all of things. JavaScript in Iframe doesn't work( onclick=functionName(defined inside iframe)... doesn't identify javascript function)
what's wrong...
this is my snippet.
//initialize
var destiframe = $('#tmpresult').contents();
destiframe.find('head').empty();
destiframe.find('body').empty();
//add script and style
destiframe.find('head').append("<style></style>");
destiframe.find('body').append('<script type="text/javascript"></script>');
//attach customized code
jQuery.each( code, function( i, code ) {
switch(i){
case 0:
destiframe.find('style').append(code.value);
break;
case 1:
destiframe.find('body').append(code.value);
break;
case 2:
destiframe.find('script').append(code.value);
break;
default:
console.log("empty set");
break;
回答1:
I think it's just my mistake.
-- If someone want to refer javascript function in iframe. iframe must refer source code which define function that component in body refer...
this is my solution..
In 'view.py', define index s
def upload_file(request): context = {'source_list':source_list,'menu_list':menu_list, 'form':fileform, 'index':1} return render(request, 'encyclopedia/maintab.html', context)In '(template document name).html', define what to do according to index.
{% if index == 0 %} <a id="nav-{{service.menu}}-tab" class="nav-item nav-link active" role="tab" data-toggle="tab" aria-controls="{{service.menu}}-tab" href="#{{service.menu}}-tab"> 목록 보기(<- this is korean. In English "show list...") </a> {% elif index == 1 %} <a id="nav-{{service.menu}}-tab" class="nav-item nav-link" role="tab" data-toggle="tab" aria-controls="{{service.menu}}-tab" href="#{{service.menu}}-tab"> 목록 보기(<- this is korean. In English "show list...") </a> {% endif %}Don't forgot to define iframe like below
<form class="form-horizontal" method ="POST" action="./upload" > ... <input type="submit" id="transferbutton" value="vvvvvvvvvvvvvvv"/> </form>In 'Urls.py'
urlpatterns = [ url(r'^encylopedia/index$', views.index, name='index'), url(r'^upload$', views.upload_file, name='upload_file'), url(r'^$', views.index, name='index'), ]
It is difficult to understand Django framework... thnks.
but it makes some blink... when click button.
来源:https://stackoverflow.com/questions/47362818/it-doesnt-work-html-and-javascript-and-iframe