开发者

JavaScript form prompt bookmark with input for Firefox

I'd like to create a bookmark for use in the toolbar of Firefox that opens a JavaScript prompt window once clicked, and asks for user input.

Firstly, is this possible to do?

Secondly, how can I submit a JS i开发者_如何学JAVAnput field to a specific PHP page for processing?

Thanks


Here is one of my bookmarks:

 var answer = prompt('Sitename?');  
 window.location.href = "http://www.ukraine.com.ua/Domains/Whois/?domain=" + answer;

I use it for viewing info for a domain.


Yes this is possible, try something like this:

# bookmarklet
<a href="javascript:var answer = prompt('What is your name?'); var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js'; head.appendChild(script); $.post('http://localhost/script.php', { name: answer });void 0;">prompt_and_post</a>

a more readable version:

var answer = prompt('What is your name?');
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
     # load jquery
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js';
head.appendChild(script);
     # do a jquery post
$.post('http://localhost/script.php', { name: answer }); void 0;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜