I need to send a mail using javascript but i was unable to do it with
can any one please help with the code.
var link == "mailto:test#test.com"
+ "&subject=" + escape(":Feedback");
window.location.h ref = link;
You assign link variable with == which is not correct. Try with:
var link = "mailto:RAS.AMB#Wilhelmsen.com&subject=" + escape(":Feedback");
window.location.href = link;
Your javascript is not valid. You have a space in href and var link == should be var link =
This works.
var link = "mailto:RAS.AMB#Wilhelmsen.com&subject=" + escape(":Feedback");
window.location.href = link;
Related
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.
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;
Hi I am developing one application in java-script. I have two pages default.aspx and addnewitem.aspx. there is one html table in default.aspx and one button. When i click on button i want to redirect to addnewitem.aspx page. I have some parameters to send in query string. I am able to redirect to addnewitem.aspx but page not found error i am getting. I am not sure why i am getting page not found error. I am trying as below.
function getValues() {
var Title = "dfd";
var PrimarySkills = "fdfd";
var SecondarySkills = "dfdf";
var url = "http://sites/APPSTEST/JobRequisitionApp/Pages/AddNewItem.aspx?Title=" + encodeURIComponent($(Title)) + "&PrimarySkills=" + encodeURIComponent($(PrimarySkills)) + "&SecondarySkills=" + encodeURIComponent($(SecondarySkills));
window.location.href = url;
}
I am checking querystring in addnewitem.aspx as below.
<script type="text/javascript">
var queryString = new Array();
$(function () {
if (queryString.length == 0) {
if (window.location.search.split('?').length > 1) {
var params = window.location.search.split('?')[1].split('&');
for (var i = 0; i < params.length; i++) {
var key = params[i].split('=')[0];
var value = decodeURIComponent(params[i].split('=')[1]);
queryString[key] = value;
}
}
}
if (queryString["Title"] != null && queryString["PrimarySkills"] != null) {
var data = "<u>Values from QueryString</u><br /><br />";
data += "<b>Title:</b> " + queryString["Title"] + " <b>PrimarySkills:</b> " + queryString["PrimarySkills"] + " <b>SecondarySkills:</b> " + queryString["SecondarySkills"];
$("#lblData").html(data);
alert(data);
}
});
</script>
"http://sites/APPSTEST/JobRequisitionApp/Pages/AddNewItem.aspx?Title=%5Bobject%20Object%5D&PrimarySkills=%5Bobject%20Object%5D&SecondarySkills=%5Bobject%20Object%5D"
I tried lot to fix this. May i know where i am doing wrong? Thanks for your help.
You should use the relative path in your url instead of hard coding the entire folder structure, which is probably incorrect since you are getting a 404. And you need to change the url every time you publish the site to the hosting enviroment when you hard code it like that.
So change
var url = "http://sites/APPSTEST/JobRequisitionApp/Pages/AddNewItem.aspx?Title=...
into
var url = "/AddNewItem.aspx?Title=...
if both the pages are in the same folder. Should AddNewItem.aspx be located in the Pages folder, you have to add that folder of course: var url = "/Pages/AddNewItem.aspx?Title=...
I am trying to add a onclick function to a button outside of the <button> tag, in Javascript. Below is what I have at the moment, but the button doesn't links to that uri when clicked. How should I do this? Many thanks for your help in advance! I commented in the code as well.
For the button I have:
"<td><button"+" id="+foodList[i].Id +" onClick="+"\"doSomething(this.id)\""+" >"+"Get"+"</button></td></tr>"
So basically I assigned the "Get" button an id in a for loop.
function doSomething(id) { //the button's id
var item = document.getElementById("type").value; //get some value from elsewhere in the page
if (item == "food") {
var uri = "baseuri" + id;
document.getElementById(id).onclick = "location.href='" + uri + "';"//add an onclick to the button so that it will takes the user to that uri
} else {
var uri = "another baseuri" + id;
document.getElementById(id).onclick = "location.href='" + uri + "';"
}
Change this:
document.getElementById(id).onclick="location.href='"+uri+"';"
to something like this:
document.getElementById(id).onclick= function(){
location.href = "Wanted url here"; // location.href = location.href + "/currentpath/additional/params/here"
}
That way, when you click the button, you have attached a function to it, and it changes the url (redirects the page)
You must write it like this :
document.getElementById(id).onclick = function() {
location.href = uri;
}
My Url looks like: http://google.com/stackoverflow/post/1
Now, I want to get just part of URL: http://google.com/stackoverflow/ and add it to code:
Post . How to do it ? Thanks !
Plz try this:
var url = "http://google.com/stackoverflow/post/1";
var partOfUrl = url.split('post')[0];
Thanks.
UPDATED:
Using JavaScript:
var url = "http://google.com/stackoverflow/post/1"; // or var url = window.location;
var matches = url.match(/^http\:\/\/([\w\.]+)\/(\w+)\/.+/);
if( matches ){
var newURL = "http://" + matches[1] + "/" + matches[2] + "/";
alert( newURL );
}
document.getElementById('post_link').href = newURL;
HTML:
<a id="post_link">post</a>
See JSFiddle
use location Object
location.href
location.pathname