在线html地址转html文本

可用于在线协议配置

页面展示

<div v-html="docHtml" />

html文本获取

function downloadDoc(url) {
    // const load = this.openInvLoading()
    let req = false
    // Safari, Firefox, 及其他非微软浏览器
    if (window.XMLHttpRequest) {
      try {
        req = new XMLHttpRequest()
      } catch (e) {
        req = false
      }
    } else if (window.ActiveXObject) {
      // For Internet Explorer on Windows
      try {
        req = new window.ActiveXObject('Msxml2.XMLHTTP')
      } catch (e) {
        try {
          req = new window.ActiveXObject('Microsoft.XMLHTTP')
        } catch (e) {
          req = false
        }
      }
    }
    const errHtml = '

Download Error!

'
if (!req) { // load.close() return Promise.reject('

对不起,你的浏览器不支持' + 'XMLHTTPRequest 对象。这个网页的显示要求' + 'Internet Explorer 5 以上版本, ' + '或 Firefox 或 Safari 浏览器,也可能会有其他可兼容的浏览器存在。

'
) } return new Promise((resolve, reject) => { req.open('GET', url, true) req.timeout = 30000 req.onreadystatechange = () => { console.log('==========(1)========>>>') if (req.readyState === 4) { // load.close() if ((req.status >= 200 && req.status < 300) || req.status === 304) { return resolve(req.responseText) } return reject(errHtml) } } req.onerror = () => { // load.close() return reject(errHtml) } req.send(null) }) } downloadDoc('https://xxxx.html').then(docHtml => { console.log('==========(html)========>>>', docHtml) })

你可能感兴趣的:(html,前端)