搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

Learn More

I've built JavaScript code that works fine in Chrome but which opens and makes active a completely blank tab in addition to the tab that my software is opening.

  • 4 回覆
  • 2 有這個問題
  • 2 次檢視
  • 最近回覆由 DIYCaptions

more options

The code in question is simply executing the following Javascript command: window.open(targetPage + youtube_id); The variables there resolve to http://diycaptions.com/php/get_captions_and_subtitles_as_text.php?id=6MBaFL7sCb8. On execution, the page opens in a tab, to be sure, but at the very same time, a second tab opens with the words about:blank in the address bar. That is the tab that becomes active, giving the appearance that the entire process failed.

As I say, this is not a problem at all in Chrome.

The code in question is simply executing the following Javascript command: window.open(targetPage + youtube_id); The variables there resolve to http://diycaptions.com/php/get_captions_and_subtitles_as_text.php?id=6MBaFL7sCb8. On execution, the page opens in a tab, to be sure, but at the very same time, a second tab opens with the words about:blank in the address bar. That is the tab that becomes active, giving the appearance that the entire process failed. As I say, this is not a problem at all in Chrome.

所有回覆 (4)

more options

Tested and open the given link, no problem observed, no additional Tab.

more options

Here's a short video clip showring the problem. https://www.screencast.com/t/Cuy1nSfOQIcv

more options

Can you post the full JavaScript code of this bookmarklet?

more options

Here's the entire script. I'll put the part that I believe triggers the problem in bold.

<script> function getYTProperties(youtube_id) {

   $.ajax({
           type:"GET",
           url:"http://gdata.youtube.com/feeds/api/videos/"+youtube_id+ "?v=2&fields=published,title,author",
           dataType:"xml",
           success: function(ytdata) {
               //popupObj = $('.yt-vid-popup')
    
               var title = $('title', ytdata).text()
               var published =  new Date( $('published',ytdata).text() )
               var channel = $('author name', ytdata).text()
               window.console.log(title, published, channel);
       },

error: function() {

}, complete: function() {

} }) }

       function parseYtUrl(target) {
           var youtube_id, targetPage, url;
           if (target === "ace") {
               var targetPage = "http://www.diycaptions.com/php/start.php?id=";

url = document.getElementById("urlid").value;

           }

if (target === "srt") {

               var targetPage = "http://get_captions_and_subtitles_as_srt?id=";

url = document.getElementById("urlidsrt").value;

           }

if (target === "text") {

               var targetPage = "http://diycaptions.com/php/get_captions_and_subtitles_as_text.php?id=";

url = document.getElementById("urlidsrt").value;

           }
           
          
           //xindow.console.log(url);
           //xlert(url.length);
           if (url.length !== 11) {
               var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
               var match = url.match(regExp);
               window.console.log(match[2]);
               if (match && match[2].length == 11) {
                   youtube_id = match[2];
               } 
           } else {
               youtube_id = url;
           }    
           getYTProperties(youtube_id);
           window.open(targetPage + youtube_id);
       }
   </script>