Forum Moderators: open

Message Too Old, No Replies

window.opener.location not working from https to http

         

dac96

1:23 am on Jun 9, 2009 (gmt 0)

10+ Year Member



Hi all

I have a real problem with an e-commerce site which has worked for years without a hitch but with the uptake of IE8 (it seems) this problem is getting more and more frequent.

Problem: customer continues through checkout on main site (http://www.example.com/checkout.php).

When they have to enter their credit card details, they click on a link to open a window (https://www.example.com/cc.php). The details are verified and if valid, the customer is returned to the confirmation page in the parent screen (http://www.example.com/thanks.php) and the payment window is closed.

Pop-up blockers are causing problems here but even when pop-up blockers are disabled, the confirmation page loads in a new window.

I'm using :

<script language="JavaScript">
<!--
window.opener.location="<?php echo ($main_url);?>thanks.php>";
window.close();
-->
</script>

I've tried as a test:

<a href="#" onclick="window.opener.location.href ='<?php echo ($main_url);?>thanks.php?'; window.close(); ">Click HERE</a>

But the page always loads in a new window and not the parent window.

Is there any way to load the confirmation page in the parent window?

Help appreciated, thanks.

[edited by: DrDoc at 4:44 am (utc) on June 9, 2009]
[edit reason] examplified URIs [/edit]

dac96

8:47 pm on Jun 9, 2009 (gmt 0)

10+ Year Member




Hoping someone can lead me in the right direction.

rocknbil

12:14 am on Jun 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard dac96, have you viewed source of the page? What do you see? Did you check this in FireFox, and looked at the error control panel? I'm suspecting you have an error there.

You have two different errors, I think.

$main_url='http://www.example.com/';

In the JS
window.opener.location="<?php echo ($main_url);?>thanks.php>";

would give you
window.opener.location="http://www.example.com/thanks.php>";

Note the errant >

When what you want is

window.opener.document.location="http://www.example.com/thanks.php";

In your inline link, you have
onclick="window.opener.location.href ='<?php echo ($main_url);?>thanks.php?'; window.close(); "

which gives you

onclick="window.opener.location.href ='http://www.example.com/thanks.php?'; window.close();"

When what you want is

onclick="window.opener.document.location='http://www.example.com/thanks.php'; window.close(); return false;"

Return false stops the link from performing it's natural action, navigating to # (top of page.) Add return false to your function too, which allows you to put the real URL in the link if JS is disabled. A couple other changes for legacy eradication:


<script type="text/javascript">
function TY_page(url) {
window.opener.document.location=url;
window.close();
return false;
}
</script>
....
<p><a href="<?php echo "$main_url/thanks.php";?>"
onclick="return TY_page('<?php echo "$main_url/thanks.php";?>');">Finish Checkout</a> </p>

Note "Finish Checkout" - never use text in links to describe how to use the document. Some user's can't "click" and click here is one of the web's "Dangerous Words".

Jesdisciple

4:37 pm on Jun 12, 2009 (gmt 0)

10+ Year Member



rocknbil: What legacy are you referring to with document.location? I've always seen and used window.location, and neither is in any formal spec.

rocknbil

9:02 pm on Jun 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not. "document.location" has nothing to do with "legacy eradication;" that's just what I've always used and works . . . more than one way to do it.

Legacy:

<script language="JavaScript">
=
<script type="text/javascript">

<!--
-->
= Not needed

^^^ This was used to hide Javascript from unsupported browsers.

<a href="#" onclick="window.opener.location.href ='<?php echo ($main_url);?>thanks.php?'; window.close(); ">Click HERE</a>

=

<a href="<?php echo "$main_url/thanks.php";?>"
onclick="return TY_page('<?php echo "$main_url/thanks.php";?>');">Finish Checkout</a>

# will just navigate to the page top; a real URL here and returning false in the onClick allows Javascript to manage the click; if JS is disabled the content is still accessible. Second, moving the actual actions to a function compartmentalizes the functions and makes the HTML easier to use. A further step would be to attach behaviors to this link in a window.onload() { }; function, rather than having an inline event handler.

"Click here"

=

Finish Checkout

Never use page text to describe the document mechanics; although it's not directly Javascript, it's still a "legacy" or "old school" waste of space.

Jesdisciple

5:22 pm on Jun 19, 2009 (gmt 0)

10+ Year Member



Grr, forgot to tick the notification box.

To clarify, I thought the bold on "document" (and "return false;") was an extended index finger.