Solved

Javasript open new page with GET parameters in the same window

Posted on 2011-02-10
3
472 Views
Last Modified: 2012-05-11
I've attempted to follow the many postings here with a similar problem, but with no success.  The main difference I see beween my situation and the other postings is the presence of GET parameters in the new url.

Below is a snippet from a javascript function I use to respond to an onclick:  I've used 'alerts' to validate that the url I build is correct.
In mainpage.php:
function change_up() {
  var new_url='secondpage.php?p1=A&p2=B';
  window.open(new_url);
}
I've also tried "_self" as the second parameter in window.open.
I've tried a few alternatives to window.open as well, such as window.href=new_url;
With the code as in the snippet above I'm getting the page I want with the parameters I want, but of course it's in a new window.  I want the new page to replace the page that the function executes from, staying in the same window.  What I'm getting on other variations is mainpage.php reloading but with the GET parameters (?p1=A&p2=B)  appended to the mainpage.url !!
What am I doing wrong, and more importantly, how do I get what I need?
Thanks!
0
Comment
Question by:JoeTodd
3 Comments
 
LVL 6

Expert Comment

by:stilliard
ID: 34866891
Works fine for me, just created a test page as just:
<script>
function change_up() {
  var new_url = 'secondpage.php?p1=A&p2=B';
  location.href = new_url;
}
</script>
<h2><a href="#" onclick="change_up(); return false;">Next Screen</a></h2>

Open in new window

And it worked fine, just to check, 1) the file url is correct, and 2) theres no javascript errors on the page?
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 125 total points
ID: 34866892
Have you tried:

function change_up() {
  location.href='secondpage.php?p1=A&p2=B';
}

or possibly:

function change_up() {
  location.href='/secondpage.php?p1=A&p2=B';
}

I hope this helps.
0
 

Author Comment

by:JoeTodd
ID: 34867287
WORKS!  Thanks for your quick reply.  I tried so many flavors of stuff that I can't be sure exactly what I used with the location.href testing earlier.  The main thing I added was the "return false" in the <a ... />  entry.  Don't know if it was essential or not.

Anyway, it's working perfectly now.

Thanks,
JOe
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Javascript cookie for whole domain 4 193
select all values from dropdown list 18 508
expanding and collapsing jquery 1 195
JavaScript issue with comma separated values 12 73
Read about the ways of improving workplace communication.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question