window.location.replace is not working - javascript

function setInit(){
iu.init({
saveFile : 'store/saveImageFile'
,CallBackOnSave : function (s){
console.log("redirect");
window.location.replace("store/details");
}
});
}
iu is an image upload module which has no issues. In fact I can see the console log of redirect.
problem is, the same page gets reloaded, instead of going to the url in replace.
tried other ways like href as well, sadly the same result.

Just use:
window.location.href = "store/details";

Maybe try:
parent.window.location.href = "store/details";

You can use by this way,
Syntax
window.location.href = window.location.host + relativePath
window.location.href = relativePath
example
window.location.href = "store/details";
window.location.href = window.location.host + 'store/details';

Related

Unable to call route through javascript function

I am trying to call a laravel route through javascript function. I have explored all the way on internet and over here but I am not finding up my solution. I referred to one answer over stack overflow about how to call route in javascript function but it didn't work for me. My route:
Route::get("edit_contact/{id}",'ContactController#edit');
Javascript function:
{
var url = '{{ route("edit_contact",":id") }}';
url = url.replace(':id', count);
document.location.href = url;
}
count is defined up in javascript which I need to pass in route.
Issue is this that it is continuously giving error..
Route [edit_contact] not defined.
All these routes are working fine when hitting through html. I have also tried to call up other routes as well through this, but none is working.
Name your route like this:
Route::get("edit_contact/{id}",'ContactController#edit')->name('edit_contact');
var routeUrl = route('posts.index');
var routeUrl = route('posts.show', {post: 1337});
// Returns results from /posts
return axios.get(route('posts.index'))
.then((response) => {
return response.data;
});
Try
let count=3
document.location.href = `edit_contact/${count}`;
try this piece. it should work:
Route::get("edit_contact/{id}",'ContactController#edit');
javascript code
<script type="text/javascript">
$("#valueid").change(function(e){
var id= e.target.value; // the id to be pass
//alert(id);
//checking the state of the domain if secured or not
if ("https:" == document.location.protocol) {
//alert('secured');
location.href="https://www.example.com/edit_contact/"+id;
} else {
//alert('not secured');
location.href="http://www.example.com/edit_contact/"+id;
}
});
</script>
In route file: (web.php)
Route::get("edit_contact/{id}",'ContactController#edit');
In js code:
Here I used count value 3 just for an example. You can use your actual value of count.
<script>
var count = 3;
var baseurl = window.location.protocol + "//" + window.location.host;
var url = baseurl + '/edit_contact/' + count;
document.location.href = url;
</script>

redirect a page from URL jquery

I want to redirect from a url. It works when I use #!, but I want to work with a parameter other than this.
//works
url = 'localhost/#!/about'
if (document.location.hash.replace(/^#?!\//, '') != '') {
loadResource(true);
}
//doesn't work
url = 'localhost/about'
if(location.pathname.replace(/^\/([^\/]*).*$/, '$1') != ''){
loadResource(true);
}
Why? Is there a way to not use #!?
The code above doesn't show any code for redirection. What does loadResource do?
Anyways, redirect in javascript is done like this:
// Syntax: document.location.href = url;
document.location.href = 'http://localhost/about';

window.location.replace() not working [duplicate]

I want to navigate to a URL on my site. This is what I have:
var TheDemoURL = window.location.host;
if (SomeCondition1) { TheDemoURL = TheDemoURL + '/fr/demo'; }
if (SomeCondition2) { TheDemoURL = TheDemoURL + '/de/demo'; }
...
window.location.replace(TheDemoURL);
Initially, in the variable watch, I have TheDemoURL: "localhost:49173" and when I alert the final TheDemoURL is looks a good URL but in reality nothing happens.
Why is this not working?
Ok, for those who come here, the solution was to add this:
var TheDemoURL = window.location.protocol + '//' + window.location.host;
Not sure if this is specific to asp.net but it made it work.
Try using
self.location = TheDemoURL;
This will take into account iframes and other weirdness.

Redirect from master page to its content pages using jquery not working

I called this method on keyUp event of enter key
function PerformSearch(search_key) {
var url = "<%=ResolveUrl("/Test/TestPage.aspx?type=search&search_key=")%>" + search_key;
//GoToLocation(url);
//window.open(url);
//$(location).attr("href", url);
//window.location.replace(url);
window.location.href = url;
}
use like this
window.location = url;
For your reference read this
You have string concatenation errors in your url.
This:
var url = "<%=ResolveUrl("/Test/TestPage.aspx?type=search&search_key=")%>" + search_key;
Should be this:
var url = "<%=ResolveUrl('/Test/TestPage.aspx?type=search&search_key=')%>" + search_key;

Get the full url including hash with content in JavaScript

How can I get url with content after hash ?
window.location return me url without hash :/
for example:
www.mystore.com#prodid=1
window.location return only www.mystore.com
window.location.hash
https://developer.mozilla.org/docs/Web/API/Window/location
Note the properties section.
Try window.location.hash this will work
this returns just content after hash
window.location.hash.substr(1);
ex: www.mystore.com#prodid=1
this will give us : prodid=1
If you only want the hash part you can use : window.location.hash
If you want all the url including the hash part, you can use : window.location.href
Regards
You have to build it up yourself:
// www.mystore.com#prodid=1
var sansProtocol = window.location.hostname
+ window.location.hash;
// http://www.mystore.com#prodid=1
var full = window.location.protocol
+ "//"
+ window.location.hostname
+ window.location.hash;

Categories

Resources