I have one SVG file that I have to show it in webpage. SVG files contains some links, on clicking links, page should be opened in new window.
1) If I use img tag like
<img id="zoom_mw" src="NC_013929_Annotation_details.svg" alt="The CRISPRmap"
data-zoom-image="NC_013929_Annotation_details.svg">
I am not able to click the links.
2) To overcome this problem I am using
<object type="image/svg+xml" data="NC_013929_Annotation_details.svg"></object>
I am able to click links.
But here the problem comes, Image should be rendered into a div of width 815px and height 815px. If I use img tag it is perfectly rendering but if I use object tag, full image is loading. Image is normally huge file may be 4500px width and height. I will use zoom feature to show user image clearly.
I need to solution to render SVG into a div of height and width 815px and links in svg file should be clickable. I am using HTML4, I cannot upgrade to HTML5.
You can load your svg file as the innerHTML of your DIV as XML using XMLHttpRequest Then compute the viewBox of the svg so it fills the DIV and is aligned top/bottom plus left/right, maintainig aspect ratio. To do this you must be able to get the svg element via it id or tag name After its loaded you should then be able to link svg elements directly to open windows as needed.
I tested the following in HTML 4.0 strict with the broswers IE11/CH31/FF23 and it works nicely.
If there's a difference in what content loads, that suggests you have some image that you reference from the svg file. Any such external references will be blocked by the browsers due to security restrictions when you use <img> for embedding the svg. However, the same svg will load all such resources when you use <object>.
If the difference is visible size, then this is perhaps a CSS problem, in which case tweaking the css until you get the svg to display at 815x815px should be enough. It is however possible that you need to add a
viewBox
attribute (set it to0 0 815 815
if that's your coordinate system) to get the svg to automatically scale to the given css viewport.You can use an svg tag and put it in an embed tag.
To scale your svg you can add attributes to the svg tag like so.
This would scale your svg to 1920 x 1000.
In order to insure your links are clickable you can add an onclick attribute to the svg group you want to make clickable and have it call a javascript function that open the new window.
Whether the link will open in a new tab or a window is browser setting specific and you can't control it. Whether or not the svg will be rendered well or even at all is also browser specific. In my experience Chrome is best at rendering svg's followed by the recent versions of IE, Firefox is OK and Safari is slow (especially on transformations and redraws if you do those).