Bookmarklet, js injection and popup issue
Posted
by Neewok
on Stack Overflow
See other posts from Stack Overflow
or by Neewok
Published on 2010-06-08T01:08:05Z
Indexed on
2010/06/08
1:12 UTC
Read the original article
Hit count: 260
JavaScript
|bookmarklet
I'm currently writing a bookmarklet that loads and executes a remote js file by appending a new <script>
tag in the current window, like so :
javascript:(function() {
if(typeof __bml_main != "undefined") return __bml_main.init();
var s= document.createElement('script');
s.type= 'text/javascript';
s.src= 'http://127.0.0.1:8000/media/bookmarklet.js';
void(document.body.appendChild(s));
})();
My bookmarklet needs to perform some dom manipulations in order to extract data from the page being viewed, and then to open a new popup to list them.
The thing is : if I want to bypass pop-up blockers, I can't open my new window from the injected script. I need to open it right from the beginning in the bookmarklet code, and to access it later when needed.
I've tried to do somehting like this :
javascript:var my_popup = window.open('http://127.0.0.1:8000/resources/manage/new/', 'newResourcePopup',config='height=200,width=400,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no');
(function() {
// script injection (...)
})();
but if I then try to access my_popup
from my remotely loaded script, most browsers will throw a security warning and won't let me access the Window object. This is understandable since the script is not from the same domain than the displayed page, but I'm kind of stuck...
A solution would be to use a div overlay, but I'd really prefer to open a window in this case.
Any hints ?
© Stack Overflow or respective owner