My situation is as follow:
I have the sites:
preview.html and index.html
Now I have some inputs and a button on preview.html, which should open the email programm using mailto and load index.html where preview.html was displayed
I have tried
window.location.href = "mailto:[myadress]?subject=[formname]&body[his inputs]";
window.location = "index.html"
Does anyone know how I could solve it?
The closest you can get client side - if the browser allows you is
window.open("mailto:[myadress]?subject=[formname]&body[his inputs]","_blank");
window.location = "index.html"
or using an iFrame:
window.iFramename.location="mailto:[myadress]?subject=[formname]&body[his inputs]";
setTimeout(function() {
window.location = "index.html";
}),1000);
but a better solution is to mail at the server and redirect
Related
For some reason, document.location.href , window.location.href , and window.location.replace is not working, I'm using localhost for now and I don't know how to redirect it to another webpage. I tried adding http:// on front, it's still not working, I tried making it redirect to another online website, It also didn't work. I read a lot of thread already and tried them but none of them worked for me.
var loginBut = document.getElementById("RDbtn1");
loginBut.addEventListener("click", checklogin);
function check(){
document.location.href = "http://localhost/some/directory/here";
alert(document.location.origin + '/some/directory'); // I just use this to know that the button is being pressed.
}
html:
<!-- some code here-->
<li><button class="login1" id="RDbtn1">LOGIN</button></li>
<!-- some code here -->
I believe you should redirect to particular html page and should give the port on which your local host application is working
document.location.href = "http://localhost:8080/some/directory/here/file.html";
It is window.location (nothing or replace or href) - document.location is normally used to get the actual page
What's the difference between window.location and document.location in JavaScript?
If you are on the same server, no need to qualify the page but I would add the actual page you try to load
window.location = "/some/directory/here/index.html"
I'm trying to redirect all my site mobile traffic to one page.
so I added redirect code in header.
<script type="text/javascript">
<!-- if (screen.width <= 699)
{ document.location = "/page/mobile/";
}
//-->
</script>
The problem is that after redirecting script continuous executing because header is the same on the whole site. so it's refreshing the page over and over again.
I want javascript to check for the /page/mobile/ in url and if it's there, do not execute redirect.
How can I achieve this? Thanks!
Do this.
if ( window.location.pathname !== "/page/mobile"){
window.location.href = "https://[your-host-name]/page/mobile";
}
So you can use window.location.pathname to access your path after host (and port)
https://developer.mozilla.org/en-US/docs/Web/API/Window/location
check window location in your if condition
if (window.location.href.indexOf("/mobile/")>-1){
console.log("You are on mobile page")
}
So, I`m working on an app in Intel XDK so if the user has no wifi connection I redirect to another page with the next script:
if (!navigator.onLine) {
window.location.replace("nowifi.html");
}
That works fine in the web browser, but in in Intel XDK does not work because of Window location (I need to add a plugin to make it work), do you know another way to redirect?
You can insert a hyperlink tag and simulate a click on it:
var link = document.createElement('a');
link.href = "http://google.com";
document.body.appendChild(link).click();
Try just location:
if (!navigator.onLine) {
window.location = "nowifi.html";
}
I'm attempting to redirect to a locally stored html file inside of my application but it just refreshes the page... I've tried a few different approach with all the same results. However, document.location.reload works.
Here are a few lines that I've already tried (url being the path to the local html file, I've tried the full url with the file:/// protocol and relative path)
document.location.href = url;
document.location = url;
window.location.href = url;
window.location = url;
window.open(url, "_self");
Thanks
I've ended up with the following solution :
var link = $("<a href='" + url + "'></a>");
$("body").append(link);
link.get(0).click();
I'm not sure these are solutions, but just some things to check for.
Ensure that you're not inadvertently redirecting to yourself (same page).
Ensure that you're not stuck in a loop because you're redirecting to a page that automatically redirects back to the original page.
If you're using jQuery Mobile, try using the page container's Change() method instead.
is there anyway through which I can open more than one email client, (on a single click) in java script, I know how to use mailto but don't know how to open multiple clients
this code opens the client on each reload.
window.location.href = "mailto:user#example.com?subject=Subject&body=message%20goes%20here";
Any help in this regard Thanks
If you want it to load the mail client on a click rather than every time the page refreshes, you want it attached to a click event, something like this :
<button class="button">Open Email</button>
Using jQuery :
$(document).ready(function(){
$('.button').on('click',function(){
window.location.href = "mailto:user#example.com?subject=Subject&body=message%20goes%20here";
});
});
Update
If you want it to load multiple instances of the client, just duplicate the window.location.href :
$(document).ready(function(){
$('.button').on('click',function(){
window.location.href = "mailto:user#example.com?subject=Subject&body=message%20goes%20here";
window.location.href = "mailto:user#example.com?subject=Subject2&body=message%20goes%20here";
});
});
It is not possible to launch external applications from JavaScript in a Browser.
mailto only launches the MUA which is configured as the default in the system-settings.