Solved

Javasript open new page with GET parameters in the same window

Posted on 2011-02-10
3
471 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
Facing problems with you memory card? Cannot access your memory card? All stored data, images, videos are lost? If these are your questions...than this small article might help you out in retrieving your lost or inaccessible data.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 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