html2canvas不支持ie,javascript - html2canvas.js not Working in IE9/10/11 - Stack Overflow

We want to capture screenshot of Div (HTML element) which is inside an IFrame. IFrame loads inside another Div at runtime in a html page. For capturing screenshot we are using html2canvas.js API.

Code is working very well with Mozilla and Chrome but not working in IE9/10/11.

The basic requirement is that to capture screenshot of Div and send that image byte-array to Flex application.

Function which captures screenshot is:

function capturImage() {

html2canvas(document.getElementById('map_canvas'), {

proxy: "server.js",

useCORS: true,

onrenderd: function (canvas) {

var imageData = canvas.todataURL('image/png', 1.0);

imageDataOnly = imageData.split(",");

falshObj.getImage(imageDataOnly[1]);

}

});

}

Error In IE:

SCRIPT438: Object doesn't support property or method

'getComputedStyle' File: html2canvas.js, Line: 2269, Column: 5

Please let me know if anyone had similar experience or has any clue in resolving the issue.

<%@ Page Language="C#" CodePage="65001" ContentType="text/html; charset=utf-8" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>3D Water Pump Model Viewer</title> <link href="Content/bootstrap.min.css" rel="stylesheet" /> <style type="text/css"> body { margin: 0; padding: 20px; background-color: #f5f5f5; } .container { max-width: 1200px; margin: 0 auto; } h1 { text-align: center; margin-bottom: 30px; } #canvas-container { width: 100%; height: 600px; border: 2px solid #ddd; border-radius: 5px; margin-bottom: 20px; background-color: #fff; overflow: hidden; } .button-group { text-align: center; margin-bottom: 20px; } .btn { margin: 0 10px; padding: 10px 20px; font-size: 16px; } </style> </head> <body> <form id="form1" runat="server"> <div class="container"> <h1>3D Water Pump Model Viewer</h1> <div class="button-group"> <button type="button" id="startBtn" class="btn btn-success">Start Motor</button> <button type="button" id="stopBtn" class="btn btn-danger">Stop Motor</button> </div> <div id="canvas-container"> <canvas id="myCanvas"></canvas> </div> </div> </form> <!-- Include Three.js library and components as ES modules --> <script type="module"> // Import Three.js modules import * as THREE from &#39;/Scripts/threejs/three.module.js&#39;; import { GLTFLoader } from &#39;/Scripts/threejs/GLTFLoader.js&#39;; import { OrbitControls } from &#39;/Scripts/threejs/OrbitControls.js&#39;; // Initialize Three.js scene var scene, camera, renderer, controls, model; var modelColor = 0xff0000; // Default red color function init() { console.log(&#39;Initializing Three.js scene&#39;); // Create scene scene = new THREE.Scene(); scene.background = new THREE.Color(0xffffff); // White background for better contrast // Create camera camera = new THREE.PerspectiveCamera(60, document.getElementById(&#39;canvas-container&#39;).clientWidth / document.getElementById(&#39;canvas-container&#39;).clientHeight, 0.1, 1000); camera.position.set(5, 5, 5); // Move camera further away and at an angle // Create renderer renderer = new THREE.WebGLRenderer({ canvas: document.getElementById(&#39;myCanvas&#39;), antialias: true }); renderer.setSize(document.getElementById(&#39;canvas-container&#39;).clientWidth, document.getElementById(&#39;canvas-container&#39;).clientHeight); renderer.setPixelRatio(window.devicePixelRatio); // Add orbit controls controls = new OrbitControls(camera, renderer.domElement); controls.enableDamping = true; controls.dampingFactor = 0.05; // Add lights var ambientLight = new THREE.AmbientLight(0xffffff, 0.5); scene.add(ambientLight); var directionalLight = new THREE.DirectionalLight(0xffffff, 0.8); directionalLight.position.set(1, 1, 1); scene.add(directionalLight); var directionalLight2 = new THREE.DirectionalLight(0xffffff, 0.5); directionalLight2.position.set(-1, -1, -1); scene.add(directionalLight2); // Add a visible grid to help with orientation var gridHelper = new THREE.GridHelper(10, 10); scene.add(gridHelper); // Add axes helper var axesHelper = new THREE.AxesHelper(5); scene.add(axesHelper); // Add a simple sphere to verify Three.js is working var sphereGeometry = new THREE.SphereGeometry(1, 32, 32); var sphereMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 }); var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial); sphere.position.set(0, 0, 0); scene.add(sphere); console.log(&#39;Sphere added to scene&#39;); // Load 3D model console.log(&#39;Starting to load model...&#39;); var loader = new GLTFLoader(); // First, check if the model file exists fetch(&#39;/3D/shuibneg.glb&#39;) .then(response => { if (response.ok) { console.log(&#39;Model file exists, starting to load...&#39;); loader.load(&#39;/3D/shuibneg.glb&#39;, function (gltf) { console.log(&#39;Model loaded successfully!&#39;); model = gltf.scene; // Remove the sphere scene.remove(sphere); // Adjust model size and position console.log(&#39;Original model bounding box:&#39;, new THREE.Box3().setFromObject(model).getSize(new THREE.Vector3())); // Center the model const box = new THREE.Box3().setFromObject(model); const center = box.getCenter(new THREE.Vector3()); model.position.sub(center); // Scale model to fit in view const size = box.getSize(new THREE.Vector3()); const maxDim = Math.max(size.x, size.y, size.z); const fov = camera.fov * (Math.PI / 180); let cameraZ = Math.abs(maxDim / 2 / Math.tan(fov / 2)); cameraZ *= 1.5; // Add a little extra space camera.position.set(0, 0, cameraZ); // Look at model const minZ = box.min.z; const cameraToFarEdge = (minZ < 0) ? -minZ + cameraZ : cameraZ - minZ; camera.far = cameraToFarEdge * 3; camera.updateProjectionMatrix(); // Apply initial color applyColor(model, modelColor); scene.add(model); console.log(&#39;Model added to scene&#39;); }, function (xhr) { console.log((xhr.loaded / xhr.total * 100) + &#39;% loaded&#39;); }, function (error) { console.error(&#39;Error loading model:&#39;, error); console.error(&#39;Error details:&#39;, error.message, error.stack); } ); } else { console.error(&#39;Model file not found:&#39;, response.status); } }) .catch(error => { console.error(&#39;Error checking model file:&#39;, error); }); // Handle window resize window.addEventListener(&#39;resize&#39;, onWindowResize, false); // Start animation loop animate(); } function onWindowResize() { camera.aspect = document.getElementById(&#39;canvas-container&#39;).clientWidth / document.getElementById(&#39;canvas-container&#39;).clientHeight; camera.updateProjectionMatrix(); renderer.setSize(document.getElementById(&#39;canvas-container&#39;).clientWidth, document.getElementById(&#39;canvas-container&#39;).clientHeight); } function animate() { requestAnimationFrame(animate); controls.update(); renderer.render(scene, camera); } // Apply color to all materials of the model function applyColor(object, color) { object.traverse(function (child) { if (child.isMesh) { if (child.material) { if (Array.isArray(child.material)) { child.material.forEach(function (material) { material.color.setHex(color); }); } else { child.material.color.setHex(color); } } } }); } // Start button click event document.getElementById(&#39;startBtn&#39;).addEventListener(&#39;click&#39;, function () { modelColor = 0x00ff00; // Green color if (model) { applyColor(model, modelColor); } }); // Stop button click event document.getElementById(&#39;stopBtn&#39;).addEventListener(&#39;click&#39;, function () { modelColor = 0xff0000; // Red color if (model) { applyColor(model, modelColor); } }); // Initialize when all resources are loaded window.addEventListener(&#39;load&#39;, init); </script> </body> </html>为什么页面上3d模型无法加载
最新发布
12-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值