1

I got a PHP index document that is loaded when I visit my site, in the address bar it doesnt show the expected www.samplewebpage.com/index.php but it just shows www.samplewebpage.com. I am using background scripts that depend on a extension to that url e.g. www.samplewebpage.com/index.php?page=index but that doesn't really work as expected since there is no /index.php to add that "variable" to.

I have looked around for some time but only found something like how to detect page load and how to change page url, but not them both in one script. I'm not sure if this is mixed Ajax and jQuery since I am not that into those yet but i'd apprechiate some help.

So I want to know how to change the url when the index page loads, I got a script that should work but doesn't.

<script type="text/javascript">
    $(document).ready(function (){
        history.pushState("", "", "www.mysamplepage.net/index.php/?page=index");
    });

</script>

note: the link is not an actual website, its just for demonstrational purposes.

EDIT: Well to fix the initial problem I just had to add an line before my script:

But how does the pushState work? I want to add "/foler/index.php/?page=index" on page load, Only if there isn't already the index.php there

Patrick Dahlin
  • 286
  • 2
  • 5
  • 19

1 Answers1

1

this test script works fine for me. my assumption is you are not loading jquery:

<html>
<head>
<title>ok</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>

test

<script type="text/javascript">
    $(document).ready(function (){
        history.pushState("", "", "www.mysamplepage.net/index.php/?page=index");
    });
</script>
</body>
</html>
skrilled
  • 5,350
  • 2
  • 26
  • 48
  • Hmm, that seems to have fixed the that the script wasn't running. But it doesn't do what I want. I just want to add /index.php/?page=index Only if it isnt there already which that code do not know. – Patrick Dahlin Feb 19 '14 at 19:32
  • ... history.pushState("", "", "index.php/?page=index"); – skrilled Feb 19 '14 at 19:35
  • If I do that then each time I refresh it adds another /index.php/ and it becomes a horribly long address after a few refreshes – Patrick Dahlin Feb 19 '14 at 19:38
  • sorry :/ is there a reason you require the url to say something specific client-side? – skrilled Feb 19 '14 at 19:40
  • I am running a script that reads the value of the ?page=index and depending on that it loads some content to the page, but when I realise the script doesn't see the change it doesn't really matter since the /index.php/?page=index appears as soon as I change page. I'll just have to default everyting back to index if there is no page variable to load from. Thanks anyway! – Patrick Dahlin Feb 19 '14 at 19:48