user1900937
user1900937

Reputation: 13

history.go (-1) not working in internet explorer

When I use the history.go(-1) command as follows it works fine, but takes very long to reaload the page.

<script type="text/javascript" language="javascript">
     javascript:history.go(-1);
</script>

But when I try and use it in my php code, it just gives me an error "Internet Explorer cannot display the webpage". Here is my code

<?php header(sprintf("Location: %s", "javascript:window.history.go(-1);")); ?>

In ff and chrome this works really well, it quickly returns to previous page, without reloading. Not so in ie.

Upvotes: 1

Views: 3273

Answers (2)

Sampson
Sampson

Reputation: 268364

The common way to go back to the previous page is not to pass JavaScript into your header, but instead to direct the user to the referer of the current page:

header("Location: " . $_SERVER["HTTP_REFERER"]);

Since you said you're using IE9, you should know that IE9 doesn't support the HTML5 History API. Moving forward you can rest assured that IE10 does support this, but for IE9 you won't be able to use these methods without using something like History.js.

If you simply want to load a page asynchronously, you can use an XHR object, or a tool like jQuery which greatly simplifies the otherwise verbose code. With jQuery you can load a page as trivially as:

$("#container").load("targetPage.php #container");

Which would load the contents of #container from targetPage.php into your #container element on the current page.

Upvotes: 5

Abhi
Abhi

Reputation: 1115

try this one:

history.back(1);

Upvotes: 0

Related Questions