Solved

Javasript open new page with GET parameters in the same window

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

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

632 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