473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Controlling windows across domains with JavaScript

Is it possible to request the user's permission to be able to control
IE or FireFox windows that are pointed to domains other than the base
domain the script is running from? For example, if my page launches a
new window pointing to a web site originating from a different domain,
is it possible for my script to request and gain access to the content
of that window, and be able to control the window?

Feb 15 '06 #1
7 5291


un******@gmail.com wrote:
Is it possible to request the user's permission to be able to control
IE or FireFox windows that are pointed to domains other than the base
domain the script is running from? For example, if my page launches a
new window pointing to a web site originating from a different domain,
is it possible for my script to request and gain access to the content
of that window, and be able to control the window?


If your own document is loaded locally (from a file: URL) in Firefox
then it is possible to try to request privileges from the user e.g.

var iframe = document.createElement('iframe');
iframe.addEventListener(
'load',
function (evt) {
try {

netscape.security.PrivilegeManager.enablePrivilege ('UniversalBrowserRead');
var p = iframe.contentDocument.createElement('p');
p.appendChild(iframe.contentDocument.createTextNod e(
'Kibology for all.'));
iframe.contentDocument.body.appendChild(p);
}
catch (e) {
// deal with not getting privilege here
}
},
false
);
iframe.src = 'http://www.mozilla.org/';
iframe.width = '100%';
iframe.height = '300';
document.body.appendChild(iframe);
If your own document is loaded via HTTP then with normal security
settings your script can't request privileges in Mozilla. You would need
signed script in that case.

IE does not allow script to request privileges but you can use HTAs
(HTML applications) where you create a .hta instead of a .html file and
install that .hta locally. Script in the HTA is not run in the normal
browser sandbox but has all access normal applications have.
With Mozilla you can also write extensions with script, if a user
installs you extension then it also has access to every API Mozilla
exposes to script.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 15 '06 #2
Thanks, thats exactly what I was looking for. Is there a cross-browser
solution that would work for this? I want to design a web site that
acts as a front end to another popular web site that alot of my friends
use. I want to be able to manipulate what is shown on the other web
site from my page. I figured I would have to write my own browser
plugin to get it to work, but I'd rather do it with javascript if I can
get user permission to have the access...

Feb 15 '06 #3


un******@gmail.com wrote:
I want to design a web site that
acts as a front end to another popular web site that alot of my friends
use. I want to be able to manipulate what is shown on the other web
site from my page. I figured I would have to write my own browser
plugin to get it to work, but I'd rather do it with javascript

As for Mozilla, a Firefox _extension_ is usually implemented using
JavaScript and XUL and/or HTML. A _plugin_ is different, that has to be
implemented in C++ usually.
Developing Firefox extensions is described here:
<http://developer.mozilla.org/en/docs/Building_an_Extension>

Cross-browser stuff is difficult, there is a Greasemonkey-Extension for
Mozilla that browser users could install, then they could install your
Greasemonkey script (JavaScript) that would be triggered each time
designted URLs are loaded:
<http://greasemonkey.mozdev.org/>
<http://greasemonkey.mozdev.org/authoring.html>

Opera since version 8 supports a similar concept, so called user scripts
that the browser user can install and which are then again triggered
when designated URLs are loaded:
<http://www.opera.com/support/tutorials/userjs/index.dml>
They claim they support Greasemonkey scripts too, not sure how good the
compatibiliy is.

I realize that Greasemonkey or user scripts are not what you originally
had in mind (your own web site accessing other web sites) but those user
scripts can be written by you and installed by your users of the other
web sites and that way you can have your scripts manipulate those web
sites as needed.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 16 '06 #4
Martin Honnen wrote:
un******@gmail.com wrote:

If your own document is loaded locally (from a file: URL) in Firefox
then it is possible to try to request privileges from the user e.g.

var iframe = document.createElement('iframe');
iframe.addEventListener(
'load',
function (evt) {
try {

netscape.security.PrivilegeManager.enablePrivilege ('UniversalBrowserRead');
var p = iframe.contentDocument.createElement('p');
p.appendChild(iframe.contentDocument.createTextNod e(
'Kibology for all.'));
iframe.contentDocument.body.appendChild(p);
}
catch (e) {
// deal with not getting privilege here
}
},
false
);
iframe.src = 'http://www.mozilla.org/';
iframe.width = '100%';
iframe.height = '300';
document.body.appendChild(iframe);
If your own document is loaded via HTTP then with normal security
settings your script can't request privileges in Mozilla. You would need
signed script in that case.


Hey Martin, thanks for that fantastic post, along with your followup.
I have a related question that's been on my mind. I've been using
GreaseMonkey, and what I've got is a local file (on my Win XP Pro hard
drive) such that when I double click it, Firefox comes up with it.
GreaseMonkey has been set to act on that file and so it does its thing
(the file on the hard drive is a dummy file. Its only point is that GM
keys on it to start the relevant GM script).

So here is my (two part) question. First: is there some kind of
privilege that I could set so that I can do a window.close() to close
down the page that I thusly brought up (I should add that the GM script
will cause other pages to be loaded in the original page's place, and
each subsequent page will also be subject to the same GM script - in
this fashion I am sequencing through pages)? I haven't worked with
privileges before. If there is some privilege that I can set, could
that privilege be set on an automated basis before Firefox is invoked
(I am effectively asking where this privilege lives) using (for
example) PHP (perhaps by editing some configuration file)? Perhaps an
extension could accomplish my goal if privilege mucking can't?

Second: assuming that the first question has a Yes answer, I would
really like the instance of FF started off by means of the double click
on my initial local file to stay hidden. This is because I want to
schedule FF to act upon that file (and hence invoke a GM script) so
that I shouldn't be distracted as this is going on.

Essentially, I want to be able to automate sequencing through web pages
on an automated basis using FF instead of IE. With IE I use VBScript
to create a hidden instance of IE, and then the VBScript gets notified
when the requested page has loaded. At that point, the script can muck
about with the loaded page using VBScript. The FF approach would allow
me to muck about with the page using the more natural javascript. And
my only remaining issues are cleanup and page visibility.

Thanks,
Csaba Gabor from Vienna

Feb 16 '06 #5


Csaba Gabor wrote:
is there some kind of
privilege that I could set so that I can do a window.close() to close
down the page that I thusly brought up
That privilege stuff stems from Netscape 4, there you (with local files)
can do e.g.

netscape.security.PrivilegeManager.enablePrivilege ('UniversalBrowserWrite');
window.close()

and if the user grants the privilege the browser window is closed.

I have just tried the same code within a Firefox 1.5 window and indeed
after the dialog comes up and the user grants the privilege the browser
window is being closed.

Of course with JavaScript 1.5 in Firefox you would then make use of
try/catch e.g.

try {

netscape.security.PrivilegeManager.enablePrivilege ('UniversalBrowserWrite');
window.close()
}
catch (e) {
// handle that privilege was not granted
}
If there is some privilege that I can set, could
that privilege be set on an automated basis before Firefox is invoked
(I am effectively asking where this privilege lives) using (for
example) PHP (perhaps by editing some configuration file)?
The dialog that comes up to ask the user to grant the privilege has a
checkbox to "remember this decision" so if the user checks that box then
Firefox safes that in some of its prefs files. I am not sure currently
which one, you might want to set up a test profile, play with that
setting and examine your prefs.js and other files respectively load the URL
about:config
and look whether any preferences are there related to that setting.
With IE I use VBScript
to create a hidden instance of IE, and then the VBScript gets notified
when the requested page has loaded. At that point, the script can muck
about with the loaded page using VBScript. The FF approach would allow
me to muck about with the page using the more natural javascript.


You can automate MS IE with JScript much the same as with VBScript, thus
if you prefer using JScript for that automation task then Windows Script
Host certainly allows that.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 16 '06 #6
Martin Honnen wrote:
Csaba Gabor wrote:
With IE I use VBScript
to create a hidden instance of IE, and then the VBScript gets notified
when the requested page has loaded. At that point, the script can muck
about with the loaded page using VBScript. The FF approach would allow
me to muck about with the page using the more natural javascript.


You can automate MS IE with JScript much the same as with VBScript, thus
if you prefer using JScript for that automation task then Windows Script
Host certainly allows that.


Excellent point. Here is an example script, complete with event
capturing. If I put the script into a test.js file and press enter on
it, then up pops an instance of IE that I can sequence through. The
reason for using DownloadComplete is that it captures document
reloading when you press the F5 key.

However, if I uncomment either of the indicated lines, then the script
sometimes gives a WScript error. This is most common when pressing
Enter twice upon the script file in rapid succession (launching two
instances at about the same time). I'm guessing it's a timing related
out of scope issue, but a more definitive statement would be great.

var objIE = WScript.CreateObject("InternetExplorer.Application ",
"IEevt_");
//objIE.Navigate("http://google.com", "", "_new", "", "");
objIE.Navigate2("http://z6.com");
objIE.visible = true;
var wsh = WScript.CreateObject("WScript.Shell");

while (objIE.readyState<4) WScript.sleep (100);

var window=objIE.document.parentWindow
// window.alert("Hi mom"); // can lead to timing / out of scope? error
wsh.popup ("Hi mom", 4, "WScript popup", 131120);

function IEevt_DownloadComplete() {
if (objIE.readyState>=2) {
// next line would show alert, but can lead to WScript errors
// objIE.document.parentWindow.alert (
// "Proper download complete: " + objIE.readyState);
objIE.document.parentWindow.setTimeout (
"alert('Proper download complete: "+objIE.readyState+"');", 100);
}
}

Csaba

Feb 20 '06 #7
Martin Honnen wrote:
That privilege stuff stems from Netscape 4, there you (with local files)
can do e.g.

netscape.security.PrivilegeManager.enablePrivilege ('UniversalBrowserWrite');
window.close()


Martin, thanks for your response. It works as indicated, when the
script is in the original file. However, it does not work with
GreaseMonkey because GM does not know 'netscape'. That is beside the
point, however, because for the (daily) automation I have in mind, the
appropriate privileges must already be in the prefs.js file (don't want
human interaction during automation).

Therefore, I can either preset into prefs.js the three 'capability'
lines that get written via the above PrivilegeManager (I think. I
didn't do rigorous testing), or I can ensure use
dom.allow_scripts_to_close_windows is set in prefs.js

With the latter, the process works well on specific invocation, but I
run into a problem when I try to automate the whole thing.
Specifically, if I schedule the base file to be run by FF (via AT
without the /INTERACTIVE flag) as User Name SYSTEM (so that I get a
fresh, hidden instance of FF), then if there is any instance of FF
already active, the SYSTEM instance will hang and not even read the
indicated file. This is not a GM issue as far as I can tell, and I've
reported it, with demo, at
https://bugzilla.mozilla.org/show_bug.cgi?id=327849

Csaba

Feb 20 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: d.schulz81 | last post by:
Hi all, We have about 10 different domains that are linked very closely and we want to identify and keep track of every single user that surfs our websites by the use of sessions. The problem...
13
by: Craig | last post by:
Hey all, Here's the situation: - two websites, one on domain1 and the other on domain2 - domain1 opens a new window which is a javascript app from domain2 - domain1 needs to communicate with...
4
by: Lefteris | last post by:
Hi, I am trying to write a simple application in javascript that automatically fills the fields of a form in a page at another domain. I display the foreign domain page on a frame and have the...
1
by: clemenr | last post by:
Hi. I would like to know if the following is feasible in JavaScript. I would create a frameset where the top frame includes JavaScript. The bottom frame would be directed to the login page of an...
1
by: KC | last post by:
Howdy, I have a SQL server in a completely different forrest than the workstation I am running query analyzer on. However in query analyzer when I choose windows authentication I cannot manually...
7
by: Doug | last post by:
An ASP.NET session cookie set on "www.mydomain.com" can not be accessed on "search.mydomain.com"; hence, a new session and cookie are being created on every sub-domain. This is occuring because...
1
by: ozgur uksal | last post by:
hi, Is there any way to upload data across domains? In other words, assume you own two domains on the same server, and the first domain, that your client visits to upload data, is going to be...
3
by: Herb | last post by:
I've found how to use javascript to embed a Windows Media Player in a web page. How do I go about controlling the player in response to user input? There should be calls to start, stop and also...
13
by: Samir Chouaieb | last post by:
Hello, I am trying to find a solution to a login mechanism for different domains on different servers with PHP5. I have one main domain with the user data and several other domains that need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.