2012-03-06 30 views
0

得到我的谷歌地圖的東西了,並運行駕駛方向等是非常滿意的,因爲我是第一次的Web開發人員。 只有一個問題,當我向客戶端(老闆)展示他喜歡它時,卻希望方向以原樣顯示,但在彈出窗口中不是單獨的選項卡。 當按下「show route」時,基本上保持地圖不變,並在彈出窗口中顯示路由信息 我已經設法獲取所有路由信息並將其顯示在可移動的div中,但這不是他要。 那麼,我所知道的任何人都會在一個單獨的彈出式窗口中僅包括方向 的東西嗎?或關於該主題的教程? 他希望儘快看到它,所以我有點反對它,任何幫助將非常感謝所有。谷歌方向只在彈出窗口中

更新:每博士作爲Molles的建議已經隱藏包含信息的原始DIV並嘗試使用下面的代碼,將其添加到彈出

enter code herefunction directionsWindow() { 
      // get the div containing the direction information from the google 
      // maps direction service 
      var divToShow=document.getElementById('directions'); 
      // store the returned div in a variable 
      var htmlToDisplay = document.getElementById('directions').innerHTML 
      // get the html contained in the div and store it in a variable 

      win=window.open('about:blank','instructions','width=1000,height=1000'); 
      // open a new window 
      doc=win.document; 
      // create a new div 
      var divToDisplay = doc.createElement('div'); 
      // set its id to directions 
      divToDisplay.id = "directions"; 
      // set its html to that of the div in the parent document 
      divToDisplay.innerHTML = htmlToDisplay; 
      // append the div to the window 
      doc.body.appendChild(divToDisplay); 
      doc.open(); 
      doc.close(); 
     } 

但這確實nt似乎工作,因爲htmlToDisplay是空的,即使我知道div存在並有內容(我可以看到它的一開始)。 任何人都可以點亮一些燈光嗎?

回答

0

打開一個窗口,並寫指令到文檔:

win=window.open('about:blank','instructions','width=300,height=200'); 
doc=win.document; 
doc.open(); 
doc.write('<div id="instructions">instructions</div>'); 
doc.close(); 
//reference to the div inside the popup 
//->doc.getElementById('instructions') 

window.open()
document.write()

+0

感謝molle博士,你知道有什麼方法可以在窗口中添加div,然後使用諸如directionsDisplay.setPanel(document.getElementById(「div_name」))之類的內容傳遞內容嗎? – user1079178 2012-03-06 11:47:28

+0

爲了使這成爲可能,彈出窗口必須打開,並且在調用setPanel()時才顯示div嗎?但是,彈出窗口打開時可能會修改上面的代碼。 – 2012-03-06 11:56:36

+0

嗯,有點工作,如果我加載子頁面時,我加載父頁面所有方向得到顯示罰款,但如果我調用子窗口函數之前directionDisplay.setPanel(doc.getElementById(「directions」));我只能得到最後一組方向(即時顯示從中央位置到其他幾個位置的路線)。我試着通過螢火蟲運行它,看看它在做什麼。 – user1079178 2012-03-06 13:00:01

0

只是爲了讓人們知道我設法在一個單獨的「窗口」我的方向。 我不得不使用jquery來顯示和隱藏我用來顯示方向的div,然後再用jquery使其可拖動。 現在可以正常工作了,我可以查看地圖上的每個路標並顯示替代根,我無法僅使用一個新的彈出窗口窗口來管理它。