3

From my child window Im trying to refresh the parent window. I tried several js functions refresh or change the parent window url and non of them gave me what I needed.

alert(window.opener.location.href);  //gave null

//all the functions bellow changed the url to 
// http://mydomain/www.google.com
window.opener.location.assign("www.google.com");
window.opener.location.replace("www.google.com");
window.opener.location.href = "www.google.com";
window.opener.location = "www.google.com";

I also tried parent.location.href but didnt change the parent url.

Is there a way I can set the parent url to the desired url? or just let it refresh the page ?Any ideas?

EDIT I cant post sample code because What Im doing is a bit complicated. Im using a salesforce button that calls a new window (asp.net page). I dont have much access to that page other than the .aspx page. Its a compiled version of a project we bought. In the .aspx page Im trying to call a js function because I dont have access to the code behind of that page. My js function is supposed to refresh the parent page once the user press on either (yes or no).

<cc1:ImageButton ID="btnNo" runat="server" OnClick="btnNo_Click" 
OnClientClick="pop()" Text="No" Width="40px" />



<script type="text/javascript" language="JavaScript">
    function pop(){

            window.opener.location.reload(true);
          //window.opener.location.href = "www.google.com";

    }

</script>
raym0nd
  • 3,172
  • 7
  • 36
  • 73

1 Answers1

2

This should work:

window.opener.location.reload(false);

EDIT

Based on your comments, it sounds like your violating the Same Origin Policy.

James Hill
  • 60,353
  • 20
  • 145
  • 161
  • @raym0nd, try passing the reload function `true` instead of `false`. This **is** the proper way to reload a parent window – James Hill Apr 27 '12 at 18:15
  • That didnt work too! Ive been trying to figure this out for the last hour with no luck. I almost tried all js functions with no luck. – raym0nd Apr 27 '12 at 18:17
  • You're going to need to post more code. A working [jsFiddle](http://jsfiddle.net/) would be best! – James Hill Apr 27 '12 at 18:19
  • What Im doing is a bit complicated. Im using a salesforce button that calls a new window (asp.net page). I dont have much access to that page other than the .aspx page. Its a compiled version of a project we bought. In the .aspx page Im trying to call a js function because I dont have access to the code behind of that page. My js function is supposed to refresh the parent page once the user press on either (yes or no). Please check the question again. I added some code. – raym0nd Apr 27 '12 at 18:24
  • Is the page you're popping up pointing to a different domain than the page that opened it? – James Hill Apr 27 '12 at 18:26
  • yea... It runs on a server different than the salesforce url. – raym0nd Apr 27 '12 at 18:27
  • 1
    See edits. Are you getting an error in the JS console that says `access denied` or something similar? – James Hill Apr 27 '12 at 18:29
  • Refused to set unsafe header "User-Agent" and Unsafe JavaScript attempt to access frame with URL blabla from frame with URL blabla Domains, protocols and ports must match. – raym0nd Apr 27 '12 at 18:32
  • Yeah, you're violating the [Same Origin Policy](http://en.wikipedia.org/wiki/Same_origin_policy). Basically, JS from one domain can't call JS on another domain. – James Hill Apr 27 '12 at 18:33
  • 1
    See http://stackoverflow.com/questions/3481977/is-there-a-way-to-bypass-javascript-jquerys-same-origin-policy-for-local-acce. Also, a quick google for `bypass same origin policy` will give you a wealth of reading. – James Hill Apr 27 '12 at 18:35
  • I think Im getting the "same origin policy" because Im trying to do `window.opener.location.reload(true);` but is there any way to use (`window.opener.location.assign("desiredURL");`) and have the url to be desiredURL instead of currentDomain.com/desiredURl ? – raym0nd Apr 27 '12 at 18:43
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10614/discussion-between-james-hill-and-raym0nd) – James Hill Apr 27 '12 at 18:45