 |
| Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 25th, 2004, 09:42 PM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Read child page form value on different domain
First time ever post.
OK. This is what I am trying to do. I have been trying to figure out how to write a javascript that will open a new page window in the background, parse/read one value from a form that is on that page. Then close the window. The window doesnât even really need to be opened; I just need that one form value. The page I would like to get this information from is not under the same domain as the parent and I donât really want to add a script to that page.
It seems like when Iâve gotten close to read the form value, I get an âAccess deniedâ error.
I also found a small script the will open a window (in front) showing the source code. Is there a way to put this window in back, parse it and close it?
Can anyone help? :(
|
|

November 25th, 2004, 10:15 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Why are you trying to read someone else's form? That's why you're getting Access Denied errors - no browser should let any user do such a thing; you may be able to retrieve passwords, credit card info, etc. It's a major security hole that I believe has been plugged awhile ago.
There is a way, however, to parse an HTML document in the background, but it requires a server language. If you have PHP I can show you how.
This is a very strange request - what kind of information are you looking to retrieve from someone else's form?
-Snib
Where will you be in 100 years?
Try new FreshView 0.2!
|
|

November 25th, 2004, 10:54 PM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, I was afraid I would get a response like that.
Long story short, this is why.
I have a unique affiliation with a manufacturer/distributor that allows me to sell their products. They host the main shopping cart and allow my to link to it. I have a store on their server (main) and also another one that I own the domain (actually I own both domains, it just costs when I need them to make changes to the one they host, so I could add a script there if I have to). Anyway, the cart software they WERE using created somewhat static pages and I was able to link to anything and everything. They have been trying to enhance the main stores appearance and I guess make it run more efficiently so now they are dynamically generating the pages.
The form I am talking about is not on a secure serve. It appears on every single page. This form is sent every time a link is clicked. It contains information such as Affialiate ID, Shopper ID and information on how to serve up the next page. One piece of information (the only piece of information) I need from this form is the Shopper ID number, which changes every time you open a new browser and start shopping. All this number does is keeps track of what they have in their shopping cart. Once the browser is closed and opened again a new number is filled into the form.
Because I am linking in from the outside, I need this number so I can update the form on my pages so everything flows together. Right now I have a script that assigns a number but the problem is that if the number I assign for the Shopper ID is the same as one that was already used and someone has already added things to the cart, they will still appear there even before this new user adds anything.
Sorry for the lengthy explanation but it was required.
|
|

November 26th, 2004, 12:18 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hii Davenic
Yes You can do this
In Two ways
1)First Method
No need of iframe/frame Even No Pop Up Window.
Only one Requirement is that client browser should ActiveX ,and i have only tested with IE
If Other browsers not supported it(ActiveX) ,it won't work :(
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
function NextQuotation() {
var obj = new ActiveXObject( "Microsoft.XMLHTTP" );
var url = "http://otherwebsiteurl/GetQuotation.asp"
obj.open( "POST",url, false );
obj.send();
nextquotation=obj.responseText
alert(nextquotation);
}
</SCRIPT>
<form name="test">
<input type="text" name="quotation_id" >
<input type=button name="getQuote" onclick="NextQuotation()">
</form>
And my "GetQuotation.asp" ASP page is like
<% response.write YourRequiredData %>
Since u want to get this YourRequiredData,You can get it
nextquotation in javascript function (i.e nextquotation=obj.responseText)
Note that,if "GetQuotation.asp",ouput other data,then you will have to parse it in your
NextQuotation() function as per ur requirement.
2)Second Method is to use iframe and retrieve that required text ,using javascript function to call iframe/frame text,u also have to parse as per ur requirement.
Hope ,It will help to find the solution.
Cheers :)
vinod
|
|

November 26th, 2004, 02:42 PM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your input Vinod. Itâs truly appreciated.
Thanks for the response I received from Snib earlier; I have been spending some time learning what I need about php. Not to mention it kind of gave me an excuse to learn a little about server side scripting.
Now I'm trying it with php and actually have it grabbing this form value I need (without opening a window). Now the problem I am having is getting this value to a cookie (only way I know right now how to pass it to my JavaScript). When I try to write it out to a cookie I a get the following error:
âWarning: Cannot modify header information - headers already sent by (output started at â¦â¦/test.php:15) in â¦â¦.test.php on line 21â.â
Where the â¦â¦ is the path to the test.php file.
Iâve done some searching about this error and found a few things like:
âyour trying to set a cookie after you've already sent a load of HTML to the browser.
Set your cookies first then, output the HTMLâ
Canât figure it out. Here is an example of my code where SOME URL is replace with mine. You can put any URL there and it will grab the text at the substr location.
<?php
$tween="";
$filename = "SOME URL";
$str_in = file_get_contents($filename);
$tween = substr($str_in, 1819, 8);
setcookie("TestCookie", $tween);
?>
The code below works. It only displays the text at the location.
<?php
$tween="";
$filename = "SOME URL";
$str_in = file_get_contents($filename);
$tween = substr($str_in, 1819, 8);
echo $tween;
?>
Just need to set a cookie with this value now. Can anyone help with this?
Thanks.
Dave
|
|

November 26th, 2004, 03:08 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Hey there,
I believe you should read Rich's FAQ about this in the PHP FAQs section.
It basically says that there is A) whitespace or any text before the very first opening <?php tag or B) you have called echo or print to output data.
You cannot set a cookie after you output data either way.
hth,
-Snib
Where will you be in 100 years?
Try new FreshView 0.2!
|
|

November 26th, 2004, 10:37 PM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Snib.
Yup.:D
That was it. Moved the code to the beginning before everything. Works like a charm.
Now I'm playing with testing to see if the cookie already exists. If it already exists I don't need to do anything. Also to test if browser is accepting cookies.
I'll play with it for a day or so but you may see me asking questions. Unless someone whats to offer now.:)
Dave.
|
|

November 27th, 2004, 07:48 AM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Snib and Vinod.
I have everything is working as planned so for.
Dave
|
|

December 2nd, 2007, 09:38 PM
|
|
Registered User
|
|
Join Date: Nov 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I know this topic is 3 years old, but I found the same situation.
I am interested to know more how to solve this issue with Iframe or any other way, but no Pop up please...
My situation is like this:
I create an iframe with src=http://otherdomain/default.aspx
That http://otherdomain/default.aspx will has a dynamic value every time I click a button (ex: If I click "Submit" button on default.aspx, it will write "Fruit: Apple", if I click again, it will update it to "Fruit: Banana"). I need that "apple" and "banana" value to be displayed on parent page.
Does it make sense?
Thank you very much :)
|
|
 |