Getting content of a script file using Javascript

前端 未结 8 1346
谎友^
谎友^ 2021-02-07 19:38

I have the following script element in my web page:


Using JavaScript,

8条回答
  •  故里飘歌
    2021-02-07 19:43

    Using an iFrame & HTML5 Local Storage

    Save the templates for rendering later...

    not stoked about the iFrame, but it seems to be working pretty good (haven't ran performance tests yet)


    Put the iFrame on the page you want the template on (index.html)

    
      
        
      
    
    
    • Make sure the src attribute is set
    • hide the element until you can get rid of it after it loads

    Put this body wrapper around your template (mustache.Users.html)

    (don't worry it won't show up in the template)

     
      
      {{#users}}
    • {{name}}
    • {{/users}}
    • replace 'users_template' with whatever name for your variable
    • the 'onload' attribute saves the template into localStorage during load

    Now You can access your templates from anywhere

    localStorage.getItem('users_template')  
    

    OR

    window.localStorage.getItem('users_template')
    

    check out this image to see it in Chrome

提交回复
热议问题