Ra************@gmail.com wrote:
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"
fill="yellow" />
</a>
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/');
}
--
Martin Honnen
http://JavaScript.FAQTs.com/