0

I am trying to redirect the user to a certain page upon registeration using the following line:

window.location.replace(value2);

where value2 is the URL. I would like to attach some message that appears as a popup window with it. Any idea how this can be achieved?

Ole Haugset
  • 3,709
  • 3
  • 23
  • 44
omarsafwany
  • 3,695
  • 8
  • 44
  • 75

3 Answers3

2

Add a GET parameter to the URL on redirection

var url= actualURL+'?message=1';
window.location.replace(url);

You can find how to retrieve get parameter from URL here

On the receiving page you can check the value of message parameter and display appropriate message from JavaScript.

By this way you can do it without server-side code change.

Community
  • 1
  • 1
Aneesh Mohan
  • 1,077
  • 8
  • 17
1

try like this

var value2 = "samp2.php?success=Yes";
window.location.replace(value2);

in samp2.php

write this in first line

if(isset($_GET['success']) && $_GET['success'] == "Yes")
{
    print '<script type="text/javascript">';
    print 'window.onload = function(e){';
    print 'alert("Welcome to page 2")';
    print '};';
    print '</script>';
}
//header("refresh:1,url=samp.php"); // this is optional
krishna
  • 4,069
  • 2
  • 29
  • 56
0

use javascript Confirm for this:

var r = confirm("Do you want to be redirected?!");
if (r == true) {
    window.location.replace(value2);
} else {
    alert( 'Okay then, We will stay right here' );
}
Ole Haugset
  • 3,709
  • 3
  • 23
  • 44
  • The scenario is as follows: button pressed on page 1 -> redirection->landing page 2 with message "Welcome to page 2" The above example will just alert on the same page with is not needed. – omarsafwany Oct 08 '14 at 10:33
  • Well, then you need to do as krishna said. A javascript on one site, cant pass along a javascript to any other site. Have your value2 param as for example: value2 = "http://www.yourdomain.com/?message=This message will be shown"; then on site 2, make a javascript that checks if the get parameter message is set, and if yes, fire an alert with its content. – Ole Haugset Oct 08 '14 at 10:35