开发者

jQuery : Running script in the address bar

In most web browsers, you can execute JavaScript in the address bar (i.e.

javascript:alert('Test');

Is it possible to execute jQuery in the ad开发者_JAVA技巧dress bar?


One word: yes :)

Use Firebug or the IE developer tools like you normally would, make sure that the current page has script references to the jQuery library, then go to town on your selectors!

It's a good way to test selectors and functionality before incorporating it into your code

EDIT: slightly mis-read the question, but the answer is still the same. Whether it's the address bar or the console window, you can use jQuery. Try putting javascript:$("#content").remove() into your address bar while viewing this page and see what happens ;)


Internet explorer address bar:

javascript:alert(eval('put any block of code here'))

This example will un-blackout wikipedia (1/18/2012)

javascript:alert(eval('$("#mw-sopaOverlay").hide(); $("#content").show();'))

You have to alert the return value of the code because IE wants to place the return value on another page.


Yep. here's an example where jquery is already on the page: https://meta.stackexchange.com/questions/20420/countdown-app-for-devdays/20430#20430

Another way you could do it is by specifying a js file that first loads the JQuery library. maybe like this: http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml


javascript:void(eval('put any block of code here'))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜