Solved

Javasript open new page with GET parameters in the same window

Posted on 2011-02-10
3
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

740 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