Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  28] [ 1]  / answers: 1 / hits: 17308  / 14 Years ago, tue, december 7, 2010, 12:00:00

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>

More From » html

 Answers
23

  1. window.open() takes a URL as a parameter. Your newWindow() function does not return anything, let alone a URL.

  2. You need to call window.open() with a valid URL passed in, which takes care of setting up the map itself.

  3. 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?


[#94704] Saturday, December 4, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austynp

Total Points: 505
Total Questions: 118
Total Answers: 106

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
austynp questions
;