在新窗口打开谷歌地图。 [英] Open google map in new window.
问题描述
我已经创建了一个Google Map API,我想在一个新选项卡(窗口)中打开它。我可以知道我的代码有什么问题吗?我可以打开一个新标签,但无法显示Google地图。
以下是我的代码。谢谢!
函数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()')>新地图(在新窗口中)< / A>
-
window.open()
带一个URL作为参数。您的newWindow()
函数不会返回任何内容,更不用说URL了。 - 您需要调用
窗口.open()
,并传入一个有效的URL,它负责设置地图本身。 如果你要附加一个
< a onclick =window.open('some_url_here'); return false;> ...< / a>。
不引人注意的JavaScript,你应该真的附加JS事件处理程序使用您的外部JS代码。
也许你想打开你的地图一个模态对话框?
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>
window.open()
takes a URL as a parameter. YournewWindow()
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?
这篇关于在新窗口打开谷歌地图。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!