简体   繁体   中英

Correct syntax for javascript redirect with parameters

I need to modify the below code that, run from Submit in a Caspio form as a popup, to redirect the parent page (instead of refreshing it) and close the popup.

The current code is:

 <script> setTimeout(function() { window.parent.location.reload(); window.parent.jQuery.fancybox.close();}, 2000); </script> 

I think something like the below is what I need but I can't get the syntax right:

 setTimeout(function() { window.parent.location.href='../my-webpage?PID=[@field:PID]&PTID=[@field:PTID]'(); window.parent.jQuery.fancybox.close();}, 2000); 

Any help on this would be greatly appreciated.

setTimeout(function(){ 
window.parent.location.href=window.location.hostname; window.parent.jQuery.fancybox.close();
}, 2000);

Its will redirect to current domain

Then for parent by "/"

var currentURL = window.parent.location.href;
var lastDir = currentURL.substr(currentURL.lastIndexOf('/') + 1)
var parentURL = currentURL.replace(lastDir,"");

   setTimeout(function(){ 
    window.parent.location.href=parentURL; window.parent.jQuery.fancybox.close();
    }, 2000);

Its will redirect to parent of domain by "/" as separator.

example my current https://stackoverflow.com/posts/parent/child

so will redirent to

https://stackoverflow.com/posts/parent

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM