2010-04-07 44 views
0

我想製作一個書籤,以便當我繼續使用Digg時,我可以簡單地點擊它,並在新標籤中打開前10個故事。Javascript Bookmarklet - 在頁面上打開多個鏈接

頁面上的HTML看起來像這樣:

<div id="topten-list"> 
    <div class="news-summary img-thumb"> 
    <h3> 
     <a href="/comics_animation/Pokemon_COMIC">Pokemon - (COMIC) 
     <span> 
     <em style="background-image: url(&quot;/comics_animation/Pokemon_COMIC/a.png&quot;);"> 
     thumb</em> 
     </span></a> 
    </h3> 
    <ul class="news-digg"> 
     <li class="digg-count"> 
     <a href="/comics_animation/Pokemon_COMIC"> 
      <strong>1872</strong> 
     </a> 
     </li> 
    </ul> 
    </div> 
    <div class="news-summary img-thumb"> 
    <h3> 
     <a href="/comedy/I_am_never_drinking_with_you_assholes_again_Pic"> 
     I am never drinking with you assholes again [Pic] 
     <span> 
     <em style="background-image: url(&quot;/comedy/I_am_never_drinking_with_you_assholes_again_Pic/a.png&quot;);"> 
     thumb</em> 
     </span></a> 
    </h3> 
    <ul class="news-digg"> 
     <li class="digg-count"> 
     <a href="/comedy/I_am_never_drinking_with_you_assholes_again_Pic"> 

      <strong>1650</strong> 
     </a> 
     </li> 
    </ul> 
    </div> 
    <div class="news-summary news-thumb"> 
    <h3> 
     <a href="/comedy/xkcd_Hell">xkcd: Hell 
     <span> 
     <em style="background-image: url(&quot;/comedy/xkcd_Hell/a.png&quot;);"> 
     thumb</em> 
     </span></a> 
    </h3> 
    <ul class="news-digg"> 
     <li class="digg-count"> 
     <a href="/comedy/xkcd_Hell"> 
      <strong>1407</strong> 
     </a> 
     </li> 
    </ul> 
    </div> 
    <div class="news-summary news-thumb"> 
    <h3> 
     <a href="/arts_culture/6_Ridiculous_History_Myths_You_Probably_Think_Are_True"> 
     6 Ridiculous History Myths (You Probably Think Are True) 
     <span> 
     <em style="background-image: url(&quot;/arts_culture/6_Ridiculous_History_Myths_You_Probably_Think_Are_True/a.jpg&quot;);"> 
     thumb</em> 
     </span></a> 
    </h3> 
    <ul class="news-digg"> 
     <li class="digg-count"> 
     <a href="/arts_culture/6_Ridiculous_History_Myths_You_Probably_Think_Are_True"> 

      <strong>1216</strong> 
     </a> 
     </li> 
    </ul> 
    </div> 
    <div class="news-summary news-thumb"> 
    <h3> 
     <a href="/people/Why_Every_Chick_Flick_Is_Starting_to_Look_The_Same_CHART"> 
     Why Every Chick Flick Is Starting to Look The Same [CHART] 
     <span> 
     <em style="background-image: url(&quot;/people/Why_Every_Chick_Flick_Is_Starting_to_Look_The_Same_CHART/a.jpg&quot;);"> 
     thumb</em> 
     </span></a> 
    </h3> 
    <ul class="news-digg"> 
     <li class="digg-count"> 
     <a href="/people/Why_Every_Chick_Flick_Is_Starting_to_Look_The_Same_CHART"> 

      <strong>978</strong> 
     </a> 
     </li> 
    </ul> 
    </div> 
    <div class="news-summary img-thumb"> 
    <h3> 
     <a href="/food_drink/WTF_World_of_FAST_FOOD_Graphic">WTF 
     World of FAST FOOD! [Graphic] 
     <span> 
     <em style="background-image: url(&quot;/food_drink/WTF_World_of_FAST_FOOD_Graphic/a.jpg&quot;);"> 
     thumb</em> 
     </span></a> 
    </h3> 
    <ul class="news-digg"> 
     <li class="digg-count"> 
     <a href="/food_drink/WTF_World_of_FAST_FOOD_Graphic"> 
      <strong>874</strong> 
     </a> 
     </li> 
    </ul> 
    </div> 
    <div class="news-summary news-thumb"> 
    <h3> 
     <a href="/people/10_Things_You_Don_t_Know_About_My_Life_As_a_Dominatrix"> 
     10 Things You Don&#39;t Know About My Life As a Dominatrix 
     <span> 
     <em style="background-image: url(&quot;/people/10_Things_You_Don_t_Know_About_My_Life_As_a_Dominatrix/a.jpg&quot;);"> 
     thumb</em> 
     </span></a> 
    </h3> 
    <ul class="news-digg"> 
     <li class="digg-count"> 
     <a href="/people/10_Things_You_Don_t_Know_About_My_Life_As_a_Dominatrix"> 

      <strong>751</strong> 
     </a> 
     </li> 
    </ul> 
    </div> 
    <div class="news-summary img-thumb"> 
    <h3> 
     <a href="/odd_stuff/Star_Trek_Transporter_Mishap_pic">Star 
     Trek Transporter Mishap (pic) 
     <span> 
     <em>thumb</em> 
     </span></a> 
    </h3> 
    <ul class="news-digg"> 
     <li class="digg-count"> 
     <a href="/odd_stuff/Star_Trek_Transporter_Mishap_pic"> 
      <strong>667</strong> 
     </a> 
     </li> 
    </ul> 
    </div> 
    <div class="news-summary vid-thumb"> 
    <h3> 
     <a href="/pc_games/StarCraft_2_Beta_Breakup_Video">StarCraft 
     2 Beta Breakup (Video) 
     <span> 
     <em style="background-image: url(&quot;/pc_games/StarCraft_2_Beta_Breakup_Video/a.jpg&quot;);"> 
     thumb</em> 
     </span></a> 
    </h3> 
    <ul class="news-digg"> 
     <li class="digg-count"> 
     <a href="/pc_games/StarCraft_2_Beta_Breakup_Video"> 
      <strong>627</strong> 
     </a> 
     </li> 
    </ul> 
    </div> 
    <div class="news-summary news-thumb"> 
    <h3> 
     <a href="/politics/Jon_Stewart_FL_Doc_Won_t_Touch_Yr_Penis_If_You_Voted_Obama"> 
     Jon Stewart: FL Doc Won&#39;t Touch Yr Penis If You Voted 
     Obama 
     <span> 
     <em style="background-image: url(&quot;/politics/Jon_Stewart_FL_Doc_Won_t_Touch_Yr_Penis_If_You_Voted_Obama/a.jpg&quot;);"> 
     thumb</em> 
     </span></a> 
    </h3> 
    <ul class="news-digg"> 
     <li class="digg-count"> 
     <a href="/politics/Jon_Stewart_FL_Doc_Won_t_Touch_Yr_Penis_If_You_Voted_Obama"> 

      <strong>508</strong> 
     </a> 
     </li> 
    </ul> 
    </div> 
</div> 

所以與類「新聞摘要」每個專區內,有一個環節。我怎樣才能讓JavaScript通過div「topten-list」並打開每個?

+0

哦,這是你所要的。我修改了帖子。覈實。 – Kronass 2010-04-07 19:48:41

回答

0

的解決方案是這樣的:我創建了一個JavaScript來穿過十佳電器列表格循環語句,並選定所有標籤命名爲「A」。

最後的書籤是這樣的:

javascript:for(i=0;i<=18;i=i+2){window.open(document.getElementById('topten-list').getElementsByTagName('a')[i]);} 

噹噹!

0

我寧願使用jQuery

但它適用於外部網站試試這個(提示我從我的上一個線程複製粘貼) 我建議創建一個頁面有兩個I幀一個導航到指定網站和其他獲取DOM對象。 在第一個導航到該網站,然後選擇其HTML和 將其追加到第二個Iframe的正文中。

iframe2.contentWindow.document.body.innerHTML = iframe1.contentWindow.document.body.innerHTML 

然後在第二個iframe中您將加載jquery腳本,您可以運行此代碼。

$("news-summary img-thumb").find("news-digg").find("a").each(
function() 
{ 
window.open(window.location + $(this).attr("href")); 
} 
) 

告訴我是怎麼回事

+0

我很想在jQuery中做到這一點,但我不確定你會如何運行jQuery或者是否將jQuery添加到網站中。 – NessDan 2010-04-07 19:09:51

+0

對不起,但我不知道如何將它寫入書籤表。代碼在那裏,但運行它是一個問題。 – NessDan 2010-04-08 05:46:20

相關問題