Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:42:05+00:00 2026-06-09T20:42:05+00:00

I have a HTML file, which is then calling a javascript file. Basic function

  • 0

I have a HTML file, which is then calling a javascript file. Basic function of the javascript file is to draw a svg file, and do modifications on it. for example

I am embedding the svg image in my JS file like this

this.my_object.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><image xlink:href="img/gauge.png" width="122" height="127"/><g id="needle" transform="rotate(0,62,62)"><circle cx="62" cy="62" r="4" style="fill: #c00; stroke: none"/><rect transform="rotate(-130,62,62)" name="arrow"  x="58" y="38" width="8" height="24" style="fill: #c00; stroke: none"/><polygon transform="rotate(-130,62,62)" points="58,39,66,39,62,30,58,39" style="fill: #c00; stroke: none"/></g><text id="value" x="35" y="103" focusable="false" editable="no" style="stroke:none; fill:#fff; font-family: monospace; font-size: 12px"></text></svg>';

Now, according to this post
Safari embeded SVG doctype

I cant inline svg image because then it wont work on safari. Now due to certain restrictions I cant embed svg file in html, it has to be accessed through javascript. Is there any way svg image can be used in javascript without using innerHTML, as finally the image has to be renedered on safari.

PS: This image has to be copied in the same folder when compiling.
https://sphotos-b.xx.fbcdn.net/hphotos-snc6/179594_10150982737360698_1827200234_n.jpg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:42:06+00:00Added an answer on June 9, 2026 at 8:42 pm

    I’m currently in Linux and can’t test with Safari, but still will post the answer…

    Try to do in this way.

    HTML:

    <div id="image-container"></div>​
    

    JavaScript:

    var container = document.getElementById('image-container'),
        image = document.createElement('img');
    image.src = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><image xlink:href="img/gauge.png" width="122" height="127"/><g id="needle" transform="rotate(0,62,62)"><circle cx="62" cy="62" r="4" style="fill: #c00; stroke: none"/><rect transform="rotate(-130,62,62)" name="arrow"  x="58" y="38" width="8" height="24" style="fill: #c00; stroke: none"/><polygon transform="rotate(-130,62,62)" points="58,39,66,39,62,30,58,39" style="fill: #c00; stroke: none"/></g><text id="value" x="35" y="103" focusable="false" editable="no" style="stroke:none; fill:#fff; font-family: monospace; font-size: 12px"></text></svg>';
    container.appendChild(image);
    ​
    

    UPDATE #1 – data URI encoding:

    The usage of unencoded data URI might be failed in IE 8 and 9.

    So you can determine the browser using navigator.userAgent and if it’s IE >= 8,
    then encode the string to Base64 before assigning it as value of image.src.

    UPDATE #2 – using object tag:

    var container = document.getElementById('image-container'),
        imageObject = document.createElement('object');
    imageObject.type = 'image/svg+xml';
    imageObject.data = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><image xlink:href="img/gauge.png" width="122" height="127"/><g id="needle" transform="rotate(0,62,62)"><circle cx="62" cy="62" r="4" style="fill: #c00; stroke: none"/><rect transform="rotate(-130,62,62)" name="arrow"  x="58" y="38" width="8" height="24" style="fill: #c00; stroke: none"/><polygon transform="rotate(-130,62,62)" points="58,39,66,39,62,30,58,39" style="fill: #c00; stroke: none"/></g><text id="value" x="35" y="103" focusable="false" editable="no" style="stroke:none; fill:#fff; font-family: monospace; font-size: 12px"></text></svg>';
    container.appendChild(imageObject);
    

    ​You can set either the data URI or direct link to .svg file location.

    object DEMO

    UPDATE #3 – CSS approach:

    var container = document.getElementById('image-container');
    container.style.width = '100px';
    container.style.height = '100px';
    container.style.backgroundPosition = 'center';
    container.style.backgroundImage = 'url(\'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><image xlink:href="img/gauge.png" width="122" height="127"/><g id="needle" transform="rotate(0,62,62)"><circle cx="62" cy="62" r="4" style="fill: #c00; stroke: none"/><rect transform="rotate(-130,62,62)" name="arrow"  x="58" y="38" width="8" height="24" style="fill: #c00; stroke: none"/><polygon transform="rotate(-130,62,62)" points="58,39,66,39,62,30,58,39" style="fill: #c00; stroke: none"/></g><text id="value" x="35" y="103" focusable="false" editable="no" style="stroke:none; fill:#fff; font-family: monospace; font-size: 12px"></text></svg>\')';
    
    ​
    

    DEMO of CSS approach

    UPDATE #4 – MIME type:

    Comment by UnderDog:

    I changed the datatype, and it worked.. but additionally I also had to
    configure web.config file to add this:

    <staticContent><mimeMap fileExtension=".svg" mimeType="image/svg+xml" /></staticContent>

    The server should send correct Content-Type header.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a embedded image in an .org file which I then publish as
I have problems with calling a JavaScript function (which is inside of an object,
I have an HTML file which is launching an app if I open it
I currently have a huge HTML file which doesn't have line breaks and just
can anyone help? I have a simple html file which i am filling via
I have a HTML file upload field from which I'm reading the file name
Let's say I'm including a file which contains html. The html have characters as
Afternoon, I am trying have an HTML file containing a frameset which contains two
I have a file which is combination of PHP and HTML. How can i
I have a JSON file which contains HTML content. I want to load it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.