2011-07-28 255 views
1

我想創建一個按鈕,將打印嵌入在網頁上打印谷歌地圖V3

看到代碼谷歌地圖:

​​

這是對我的地圖的DIV

<div id="map_canvas" style="width:800px; height:500px;"></div> 

,這是打印按鈕

<input type="button" value="Print" onclick="print()"> 

當我點擊打印按鈕時,我得到一個錯誤「window.opener爲空」。 什麼是打印地圖的正確代碼?

回答

-1

檢查是否包含地圖上主窗口DIV都具有ID的div =「map_canvas」的

0

window.opener返回到創建窗口的窗口的引用。因爲你沒有創建任何新窗口,所以在這裏不需要window.opener。

直接使用window.document.getElementById。

試試這個:

function print(){ 
    var contents = window.document.getElementById("map_canvas"); 
    document.write(contents.innerHTML); 
    window.print(); 
    } 
0
var content = window.document.getElementById("map-canvas"); // get you map details 
var newWindow = window.open(); // open a new window 
newWindow.document.write(content.innerHTML); // write the map into the new window 
newWindow.print(); // print the new window 
+1

能否請您詳細闡述更多的答案增加關於您所提供的解決方案多一點的描述? – abarisone