473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SVG and JavaScript

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?

Mar 5 '06 #1
4 2895


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/
Mar 6 '06 #2
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.

Mar 7 '06 #3

Ra************@gmail.com wrote:
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?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 7 '06 #4
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

Mar 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.