473,846 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5332


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.create Element('iframe ');
iframe.addEvent Listener(
'load',
function (evt) {
try {

netscape.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lBrowserRead');
var p = iframe.contentD ocument.createE lement('p');
p.appendChild(i frame.contentDo cument.createTe xtNode(
'Kibology for all.'));
iframe.contentD ocument.body.ap pendChild(p);
}
catch (e) {
// deal with not getting privilege here
}
},
false
);
iframe.src = 'http://www.mozilla.org/';
iframe.width = '100%';
iframe.height = '300';
document.body.a ppendChild(ifra me);
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.mozil la.org/en/docs/Building_an_Ext ension>

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.mo zdev.org/>
<http://greasemonkey.mo zdev.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.create Element('iframe ');
iframe.addEvent Listener(
'load',
function (evt) {
try {

netscape.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lBrowserRead');
var p = iframe.contentD ocument.createE lement('p');
p.appendChild(i frame.contentDo cument.createTe xtNode(
'Kibology for all.'));
iframe.contentD ocument.body.ap pendChild(p);
}
catch (e) {
// deal with not getting privilege here
}
},
false
);
iframe.src = 'http://www.mozilla.org/';
iframe.width = '100%';
iframe.height = '300';
document.body.a ppendChild(ifra me);
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.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lBrowserWrite') ;
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.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lBrowserWrite') ;
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 DownloadComplet e 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.CreateO bject("Internet Explorer.Applic ation",
"IEevt_");
//objIE.Navigate( "http://google.com", "", "_new", "", "");
objIE.Navigate2 ("http://z6.com");
objIE.visible = true;
var wsh = WScript.CreateO bject("WScript. Shell");

while (objIE.readySta te<4) WScript.sleep (100);

var window=objIE.do cument.parentWi ndow
// window.alert("H i mom"); // can lead to timing / out of scope? error
wsh.popup ("Hi mom", 4, "WScript popup", 131120);

function IEevt_DownloadC omplete() {
if (objIE.readySta te>=2) {
// next line would show alert, but can lead to WScript errors
// objIE.document. parentWindow.al ert (
// "Proper download complete: " + objIE.readyStat e);
objIE.document. parentWindow.se tTimeout (
"alert('Pro per download complete: "+objIE.readySt ate+"');", 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.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lBrowserWrite') ;
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 PrivilegeManage r (I think. I
didn't do rigorous testing), or I can ensure use
dom.allow_scrip ts_to_close_win dows 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
4475
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 is how to keep track of the session ID across domains. - cookies don't work because not acepted by 40 % of or users and cookies don't work across domains
13
4300
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 the javascript app on domain2 The problem occurs in that last step. Browsers don't allow script access across domains for security reasons, rightly so. Nonetheless, I still
4
9549
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 javascript code in the parent (where the frameset is defined). I have set the "Access to data sources across domains" to "enable" in my security settings for the local intranet. The main frame page and the javascript is on the intranet. I even...
1
1897
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 existing content management system. The javascript would then fill in the login name and password of the form, and submit the form to log in. If this works then the bottom frame would be replaced with another page requesting that a link be...
1
1768
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 specify "domain\username" as I could when mapping a file share across domains or forests. Is there any way around this without resorting to using SQL Server authentication? Thanks
7
7779
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 ASP.NET always sets the Session cookie domain to the full domain (e.g. "www.mydomain.com") instead of the parent domain (e.g. "mydomain.com") The problem with this is when the visitor goes to a different sub-domain (e.g. "search.mydomain.com"),...
1
1848
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 out of web space, and you want to use the other domain to store data. Since, your php upload script is on the first domain, is there any way to make your php code to upload data to the second domain that contains enough web space (across domains)? ...
3
13497
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 to play at a certain position. For instance, I'd like to have a video playing. Along with that, I'd present a list of 10 chapters within the video. When a user clicks a link, the player should play the appropriate chapter or section. Thanks.
13
8690
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 a login to show data. I want the user to login only once when he visits any of my domains.
0
9879
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10976
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10705
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9477
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5714
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5906
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4111
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.