Open google map in new window.
function, google-maps, html, javascript
Solution
- `window.open()` takes a URL as a parameter. Your `newWindow()` function does not return anything, let alone a URL.
- You need to call `window.open()` with a valid URL passed in, which takes care of setting up the map itself.
If you're going to attach an event handler inline, do it right:
`<a onclick="window.open('some_url_here'); return false;">...</a>.`
That said, in the interest of unobtrusive JavaScript, you should really attach JS event handlers using your external JS code.
Perhaps you want to open your map in a modal dialog instead?
Problem
I have created a Google Map API and I would like to open it in a new tab(Window). May I know what's wrong with my code? I can open a new tab, but I can't display the Google Map. Below are my code. Thanks! ``` function newWindow() { var myLatlng = new google.maps.LatLng(0.7,40); var myOptions = { zoom: 2, center: myLatlng, mapTypeId: google.maps.MapTypeId.HYBRID }; map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } <A HREF="" onclick="window.open('javascript:newWindow()')" >New Map(In new window)</A> ```