SVG and JavaScript

R

Raoul.Kamadjeu

I'm trying to open a new window from an SVG document (a map). A new
window will popup when the user clicks on an SVG polygon.
The SVG document is generated by a php function
The JavaScript function resides on an external file

function open_me(url) {
window.open('url');
}

I use this piece of code to open the new window
<a href="javascript:(void)" onclick="open_me('http://www.google.com');"
target="_blank">

This doesn't work. I got the error message "window.open is not a
function".
I tested the same routine with window.alert and it works fine.
What is wrong here?. Why window.open is not recongnized as a function
in this case and window.alert is?
 
M

Martin Honnen

I'm trying to open a new window from an SVG document (a map). A new
window will popup when the user clicks on an SVG polygon.
The SVG document is generated by a php function
The JavaScript function resides on an external file

function open_me(url) {
window.open('url');
}

I use this piece of code to open the new window
<a href="javascript:(void)" onclick="open_me('http://www.google.com');"
target="_blank">

Why don't you simply use an SVG link element to open the new window e.g.
<a xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="http://example.com/"
xlink:type="simple"
target="_blank">
<rect x="10" y="10"
with="30" height="30"
This doesn't work. I got the error message "window.open is not a
function".
I tested the same routine with window.alert and it works fine.
What is wrong here?. Why window.open is not recongnized as a function
in this case and window.alert is?

Depending on the SVG implementation that window object might simply not
implement a method named open. If the SVG is embedded inside of an HTML
document in a browser where the window object supports a method named
open then try e.g.
if (typeof window != 'undefined' &&
typeof window.open != 'undefined'
{
window.open('http://example.com');
}
else if (typeof parent != 'undefined' &&
typeof parent.open != 'undefined')
{
parent.open('http://example.com/');
}
 
R

Raoul.Kamadjeu

Thanks for your reply. I implemented the piece of code you proposed .
The error message doesn't show anymore, but the page doesn't pop up.
 
M

Martin Honnen

I implemented the piece of code you proposed .
The error message doesn't show anymore, but the page doesn't pop up.

Which software is used to render the SVG and execute the script?
 
R

Raoul.Kamadjeu

The SVG map was obtained by converting MapInfo shape file into SVG,
using Map2Svg.
The SVG map is embeded into a php file. I used Internet Explorer 6
(Adobe SVG Viewer). The fill property of the SVG polygons are
controlled by a php function, based on the district coverage value
returned by a query to a MySQL database
You can get an overview of this project at
http://www.melen-medicus.info/afro_map_machine/
Select a country, an antigen and a year. I want the user to access
additional information by clicking on a district polygon.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top