开发者

Writing js bookmarklet to navigate to site, fill in fields with previous page information

开发者 https://www.devze.com 2023-01-06 09:12 出处:网络
I\'m writing this bookmarklet in Javascript, which is also calling some JQuery objects. The goal here is to pull the page title, URL and any currently selected text, then fill them into fields on the

I'm writing this bookmarklet in Javascript, which is also calling some JQuery objects. The goal here is to pull the page title, URL and any currently selected text, then fill them into fields on the target page.

The problem is that it only works when I'm on the page with the fields I'm trying to fill in! I've tried everything but I'm at a loss. Can anyone help me out? Here's the code:

javascript: (function() {
title = document.title;
url = document.URL;
text = document.getSelection();
w = window.open('My site');
w.onload = function run() {
    w.$('#id_title').val(title);
    w.$('#id_url').val(url);
    w.$('#id_description').val(text);
}
})();

Any help is greatly appreciated, as I'm a a js novic开发者_高级运维e.


I believe you are hitting a X-site scripting security measure. A page from site A can't modify a page from Site B.

And/or you are using jQuery to set values in the popup window... is jQuery loaded in the main source window? or do you load it yourself?

0

精彩评论

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