SVG + PHP + Javascript

I am trying to create a generated PHP SVG, but I am already stuck in displaying an SVG file with Javascript in it. Javascript is a pan and zoom function.

Code:

<? header("Content-Type: image/svg+xml"); ?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"> <script xlink:href="SVGPan.js"/> <g id="viewport" transform="translate(200,200)"> <polygon points="50,125 100,100 150,125 100,150" fill="green" stroke="black" stroke-width="1" /> </g> </svg> 

By opening this in Internet Explorer, I can pan, but I cannot zoom.

By opening this in Google Chrome, the script works correctly, it displays, I can zoom and pan, but I get an error

error in row 10 in column 1: additional content at the end of the document

I searched google for it and stackoverflow, but I can not find a solution.

Could you help me with this?

+4
source share
1 answer

I see that you get the added analytics code, which causes additional output at the end of the file. Usually, even free hosts do not put this in a file when it gains access to the correct MIME type. You may need to ask their support how to get the mime image / svg + xml type, which will be used as the mime text / javascript type (i.e., without adding analytics code). I have never used them, but cPanel and other popular control systems allow you to control MIME types for many other reasons, including this one.

0
source

Source: https://habr.com/ru/post/1437216/


All Articles