iframe嵌套页面 跨域 跨页面获取DOM和跨页面调用jquery的wordExport方法

vue页面:
<template>
    <div class="showbox">
        <!-- 表单查看 -->
        <div class="top_main" id="a">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item >调查任务</el-breadcrumb-item>
                <el-breadcrumb-item >调查详情</el-breadcrumb-item>
                <el-breadcrumb-item >查看表单</el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <div class="main_box">
            <div class="btn_main">
                <div>调查表单</div>
                <div>
                  <el-button class="styleBtn" id="btnWord" type="primary" @click="btnWord">导出word</el-button>
                    <el-button class="styleBtn" type="primary" @click="close">返回</el-button>
                </div>
            </div>
            <!-- 填写表单 -->
            <div class="from_main">
                <iframe ref="iframe" id="iframe" name="iframe" style=" width: 100%;height: 800px;" :src="fromUrl" >                         </iframe>
            </div>
        </div>

    </div>
</template>

 

 

<script>
  import '../../../static/js/jquery-1.11.1.min'
  import saveAs from 'file-saver';
  import '../../../static/js/FileSaver'
  import '../../../static/js/jquery.wordexport'
import {mapGetters} from 'vuex'
  // import saveAs from "file-saver"
  // import '@/components/FileSaver';
  // import '@/components/jquery-1.11.1.min';
  // import '@/components/jquery.wordexport';

// import axios from "axios";
var config = require('@/components/utils/Common_Config.js');
var Cookies =require("js-cookie");
    export default{
        data(){
            return {
                fromsId:'',
                fromUrl:'',
                outData: {},
                myUrl:"",
            }
        },
        computed:{
            ...mapGetters(['location'])
        },
        methods:{
            close(){
                console.log("要返回这个页面:"+this.location)
                 this.$router.push({path: this.location});//跳到列表页
                // this.$router.go(-1);
            },
          // btnWord() {
          //   var obj = document.getElementById("iframe").contentWindow;
          //   alert(obj.document.getElementById("dwSurveyName").innerText)
          //   // alert(obj.document.getElementById("dw_body_content").innerHTML)
          //   console.log(obj.document.getElementById("dw_body_content").innerHTML)
          //   // alert(obj.document.getElementById("dwSurveyName").value)
          //   // console.log(obj.document.getElementById("dwSurveyName").innerText)
          //   var fileName = obj.document.getElementById("dwSurveyName").innerText
          //   var content = obj.document.querySelector("dw_body_content")
          //     var that = this;
          //   axios.post(config.apiHost + "/exportWord/makeCaseDoc",{
          //     fileName: fileName,
          //     content: content
          //   }).then((res)=>{
          //     if (res.data.status == 200) {
          //       window.open(res.data.body.completeSavePath,'_blank')
          //     } else {
          //       that.$message.error(res.data.body.message);
          //     }
          //   });
          // }

          btnWord() {
            alert(jQuery.fn.jquery);
            // alert($('#a').wordExport)
            // console.log($('#a').wordExport)
            // $('#a').wordExport("标题")

            var obj = document.getElementById("iframe").contentWindow;
            var fileName = obj.document.getElementById("dwSurveyName").innerText;
            // obj.document.getElementById("dw_body_content").wordExport(fileName ,'');
            console.log(obj.$("#dw_body_content"))
            console.log('word77',obj.$("#dw_body_content").wordExport)
            // window.open(obj.$("#dw_body_content").context.URL, '_blank')
            // obj.$("#dw_body_content").wordExport(fileName)
            var obj2 = obj.$("#dw_body_content")
            console.log('obj:',obj2)
            console.log('obj函数:',obj2.wordExport)
            // obj.$("#dw_body_content").wordExport(fileName)
            obj2.wordExport(fileName)
          },

        },
        created(){
            // console.log("输出表单Id");
            this.formId=this.$route.params.formId;
            this.eventId=this.$route.params.eventId;
            this.caseType=this.$route.params.caseType;
            this.caseId=this.$route.params.caseId;
            // http://192.168.1.169:8020/cdcform
            this.fromUrl=config.apiUrl+ "preview_answer.html?formId="+this.formId+"&eventId="+this.eventId+"&caseType="+this.caseType+"&caseId="+this.caseId+"&token="+Cookies.get('token');
            // console.log(this.fromsId);
          console.log('vuex',this.$store);
          console.log('route',this.$route);
        }
    }
</script>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值