Solved

Javasript open new page with GET parameters in the same window

Posted on 2011-02-10
3
470 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now