1

I have two different hidden divs. They are hidden with css "display:none;". Both of the divs contains a single image. Upon page load I would like div 1 to be shown for a short period of time if the url is "www.myserver.com/index.php?succeded=yes" and div 2 to be shown instead if the url says "www.myserver.com/index.php?succeded=no".

Can this be done with jquery?

Cyberlurk
  • 766
  • 3
  • 9
  • 30

4 Answers4

2

To read "succeded": Get escaped URL parameter.

Using the function function getURLParameter(name):

if (getURLParameter('succeded') == 'yes') {
    $('#mydiv').show();
    window.setTimeout(function () { $('#mydiv').hide(); }, 5000); // hide after 5s
}

that should do the trick.

Community
  • 1
  • 1
agrafix
  • 765
  • 1
  • 5
  • 15
1

You can use .split() method of jQuery:

var url = "www.myserver.com/index.php?succeded=yes"; // window.location.href;
var str = url.split('?')[1];

if(str == "succeded=yes"){
    $('.yesdiv').show().delay(2000).hide();
}else{
    $('.nodiv').show().delay(2000).hide();
}
Jai
  • 74,255
  • 12
  • 74
  • 103
  • Also consider the following [question](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values). – hitautodestruct Apr 11 '13 at 12:42
  • Yup thats great but OP asked "`Can this be done with jquery?`". so this is the way to get it with jquery. – Jai Apr 11 '13 at 12:50
0

First of all, parameters in the URL are GET parameters, not POST.

And of course this can be done – either you already check for this parameter server-side and then just output the appropriate JS code; or you check the URL of the current document in JS yourself, using location.search to access the query string part of the URL.

CBroe
  • 91,630
  • 14
  • 92
  • 150
0

i think it would be easier if you parse the php variable to js

var any = "<?=isset($_GET['success'])?$_GET['success']:''?>";
Lesonschi
  • 74
  • 4