Reputation: 9081
I have an asp.net mvc application in which i need to redirect to another page:
<script>
$(function () {
$('.Enregistrer').click(function () {
window.location.href ="www.google.com";
});
});
</script>
i used window.location.href
, location.href
, location.replace
and location
to try to redirect but it didn't work in two different browser (Chrome && IE)
What are the reasons? how can i fix it?
Upvotes: 0
Views: 470
Reputation: 337560
You need to include the protocol (eg. http://
) in the domain, otherwise it is assumed to be a local request:
<script type="text/javascript">
$(function () {
$('.Enregistrer').click(function (e) {
e.preventDefault(); // this may be required
window.location.assign("http://www.google.com");
});
});
</script>
Note I also added the type
attribute to the script
tag, and used window.location.assign
as these are common best pratices.
Also, if .Enregistrer
is an a
element you may need to include event.preventDefault
to stop the normal link behaviour.
Upvotes: 1
Reputation: 15387
Try this, Some browser didn't understand language
<script type="text/javascript">
$(function () {
$('.Enregistrer').click(function () {
window.location.href ="www.google.com";
});
});
</script>
Upvotes: 1