Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

It doesn't work (html and javascript and Iframe)

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;

result.

result2. with console.log

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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..

  1. 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) 
    
  2. 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 %}
    
  3. Don't forgot to define iframe like below

    <form class="form-horizontal" method ="POST" action="./upload" >
        ...
        <input type="submit" id="transferbutton" value="vvvvvvvvvvvvvvv"/>
    </form>
    
  4. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...