最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I start a function in a new tab using a bookmarklet? - Stack Overflow

programmeradmin2浏览0评论

This is my first time taking a shot at JavaScript, so excuse me if it seems a bit rough.

This website / provides a bookmark with JavaScript that allows you to download video off of YouTube and other media sites by clicking on it when on the media page. However, I found that instead of opening the download page in a new tab, it opens it in the current one, interrupting the media (probably to encourage you to buy their pro version).

Seeing it as a chance to try out JavaScript (as I have only used bookmarklets before), I have been searching for answers, but the ones I found seem to only have worked with older versions of the website, as the JavaScript seems updated.

I have been trying to make a bookmarklet that opens a new page, and then loads the download page for the media.

The first code I encountered as a solution was: javascript:void(window.open('/?url='+escape(window.location)));

But this didn't work, which was when I noticed that the bookmarklet's final URL added &bm=y to the end of the URL, so I edited it to:
javascript:void(window.open('/?url='+escape(window.location)+'&bm=y'));

I then looked at the bookmarklet's original code::
javascript: (a%20=%20(b%20=%20document).createElement('script')).src%20=%20'.js',%20b.body.appendChild(a);void(0);

and realized that it was calling on an external script (I believe) and that it would have to stay intact.

And from their I have been trying various methods at getting this to work, and so far, this is what I have: javascript:void(window.open(window.location));void((a%20=%20(b%20=%20document).createElement('script')).src%20=%20'.js',%20b.body.appendChild(a));

This script opens a new tab, but the new tab will only be a copy of the YouTube video, and the original tab will load the download page, which still interrupts the media, rendering my work useless, if slightly more convenient.

I have been trying every way I can, but it seems like I can't have a second script in the same bookmarklet without it pointing to the original tab it was called in.

So, I have been wondering what it is I need to do in order to: 1. Create a new tab 2. Have the new tab load the download page (instead of the original) 3. Leave the original tab alone and use it only to capture the window.location

If this is impossible to do, is their a way to have a bookmarklet in the toolbox that makes a copy of the original page and then points to a bookmarklet in the bookmarks menu that contains the redirect to the download page?

This is my first time taking a shot at JavaScript, so excuse me if it seems a bit rough.

This website http://www.keepvid./ provides a bookmark with JavaScript that allows you to download video off of YouTube and other media sites by clicking on it when on the media page. However, I found that instead of opening the download page in a new tab, it opens it in the current one, interrupting the media (probably to encourage you to buy their pro version).

Seeing it as a chance to try out JavaScript (as I have only used bookmarklets before), I have been searching for answers, but the ones I found seem to only have worked with older versions of the website, as the JavaScript seems updated.

I have been trying to make a bookmarklet that opens a new page, and then loads the download page for the media.

The first code I encountered as a solution was: javascript:void(window.open('http://keepvid./?url='+escape(window.location)));

But this didn't work, which was when I noticed that the bookmarklet's final URL added &bm=y to the end of the URL, so I edited it to:
javascript:void(window.open('http://keepvid./?url='+escape(window.location)+'&bm=y'));

I then looked at the bookmarklet's original code::
javascript: (a%20=%20(b%20=%20document).createElement('script')).src%20=%20'http://keepvid./js/bm.js',%20b.body.appendChild(a);void(0);

and realized that it was calling on an external script (I believe) and that it would have to stay intact.

And from their I have been trying various methods at getting this to work, and so far, this is what I have: javascript:void(window.open(window.location));void((a%20=%20(b%20=%20document).createElement('script')).src%20=%20'http://keepvid./js/bm.js',%20b.body.appendChild(a));

This script opens a new tab, but the new tab will only be a copy of the YouTube video, and the original tab will load the download page, which still interrupts the media, rendering my work useless, if slightly more convenient.

I have been trying every way I can, but it seems like I can't have a second script in the same bookmarklet without it pointing to the original tab it was called in.

So, I have been wondering what it is I need to do in order to: 1. Create a new tab 2. Have the new tab load the download page (instead of the original) 3. Leave the original tab alone and use it only to capture the window.location

If this is impossible to do, is their a way to have a bookmarklet in the toolbox that makes a copy of the original page and then points to a bookmarklet in the bookmarks menu that contains the redirect to the download page?

Share Improve this question asked Apr 28, 2012 at 10:25 YljYlj 451 silver badge7 bronze badges 3
  • Don't have a technical solution for you, but as far as a better bookmarklet for downloading videos, you may want to check out this: deturl./… – DG. Commented Apr 28, 2012 at 12:41
  • Another ment. Your 1st bookmarklet worked for me when I tested on YouTube with Firefox. Please note that in Firefox you can not paste bookmarklet code into the URL for testing the way you used to be able to do. You must enter it into an actual bookmark first. In Chrome you can only do it if you manually type "javascript:" first. If you try to paste the bookmarklet code, the "javascript:" part will be removed. – DG. Commented Apr 28, 2012 at 12:46
  • First off, I just checked out the link you gave me, and that seems like a very good bookmarklet to download YouTube videos. But at the moment, I really just want to solve this problem to see what I can do with JavaScript. Second, just to clarify, whenever I made an edit to the JavaScript, I would paste it into the bookmark, not the URL. And about the first bookmarklet working, I'll throw you the picture parison I gave "mplungjan". (Picture of KeepVid Code) | (Picture of my code). Notice the difference in the list of downloads? – Ylj Commented Apr 28, 2012 at 19:53
Add a ment  | 

3 Answers 3

Reset to default 4

Copy this text: http://keepvid./js/bm.js

Change

<form method='post' 

to

<form method='post' target='_blank'

You can host the file on your own server and append the script in the same manner as the original bookmarklet, or you can press the code into a stand alone bookmarklet like this

javascript:eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return%20r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new%20RegExp('\\b'+e(c)+'\\b','g'),k[c]);return%20p}('o%20i(a,b,c){N{7%20u=a.v(b);7%20w=u[1].v(c);x%20w[0]}O(P){x\'\'}}o%20p(){7%20q=d.Q("R");q.9="<z%20S=\'T\'%20U=\'V\'%20W=\'r://A.g/?B="+C(h.j)+"&X=y\'%20Y=\'D\'><k%20l=\'s\'%20t=\'Z\'%20m=\'"+8+"\'%20/><k%20l=\'s\'%20t=\'2\'%20m=\'"+2+"\'%20/><k%20l=\'s\'%20t=\'5\'%20m=\'"+5+"\'%20/><k%2010=\'11-12-E%20F-G-13%20F-G-14\'%20l=\'H\'%20m=\'15%2016%2017\'%20/></z>";d.e.19(q);h.1a["D"].H()}7%20d=h;6(d.j.I.1b(/J.g/i)){7%208=i(d.e.9,\';8=\',\'&\');6(8==\'\')8=i(d.e.9,\'"8":%20"\',\'"\');7%202=i(d.e.9,\'2"%201c="\',\'"\');6(2==\'\')2=i(d.e.9,\'1d"%202="\',\'"\');7%205=i(d.e.9,\'n=\',\'&\');6(5==\'\')5=i(3.f,\'n":%20"\',\'"\').K("\\\\/","/");6(5==\'\'){7%203=1e;6(!3&&1f%20L!=\'1g\'){3=E%20L()}3.1h("1i","r://1j.J.g/1k?8="+8+"&5=18",1l);3.1m=o(){6(3.1n==4){2=i(3.f,\'&2=\',\'&\');6(2==\'\')2=i(3.f,\'2=\',\'&\');5=i(3.f,\'n=\',\'&\');6(5==\'\')5=i(3.f,\'n":%20"\',\'"\').K("\\\\/","/");p()}};3.1o()}M{p()}}M{h.j.I=\'r://A.g/?B=\'+C(1p.j)}',62,88,'||title|kvajax||fmt|if|var|video_id|innerHTML||body|responseText||document||location|input|type|value|fmt_stream_map|function|finishkv|gd|http|hidden|name|a1|split|a2|return||form|keepvid|url|escape|kvdl|new|yt|uix|submit|href|youtube|replace|XMLHttpRequest|else|try|catch|err|createElement|div|method|post|target|blank|action|bm|id|vid|class|master|sprite|button|tooltip|Download|with|KeepVid||appendChild|forms|match|content|ltr|false|typeof|undefined|open|GET|www|get_video_info|true|onreadystatechange|readyState|send|window'.split('|'),0,{}))

I packed it using this: http://javascriptpressor./

For treating non-youtube sites in the same manner, also change

document.location.href='http://keepvid./?url='+escape(window.location);

to

window.open('http://keepvid./?url='+escape(window.location));

This question is a bit old, but my little bookmarklet to open dict in a new tab fits perfectly to the question title.

javascript:(function(){window.open("http://www.dict/?s="+encodeURIComponent(prompt("Enter word to look for:")))})();

I'm not sure what the wrapper function does, but without it, the current tab will get cleared.

Src: https://www.mattcutts./blog/javascript-bookmarklet-basics/

The first code I encountered as a solution was: javascript:void(window.open('http://keepvid./?url='+escape(window.location)));

But this didn't work

Did not work in what way? If the browser is blocking popups, you will not succeed. If it does not, that method should work.

Here is a possible other method - still not guaranteed to work any better

You need to store a script on your server. The script is loaded into the current window using

(function() {var scr=document.createElement('script');scr.src='http://www.yourserver./yourserverprocess.php?loc=escape(window.location.href;document.getElementByTagname('head')[0].appendChild(scr); })();

then on your server you can return (assuming php)

header("content-type: text/javascript");
echo "window.open('http://yourserver./convert.php?loc=".$_GET["loc"],'_blank')";
发布评论

评论列表(0)

  1. 暂无评论