I have this javascript snippet which passes an id and the reffering page to a php page where i then collect the ip address, what i wanted to do is also capture the page meta title and also forward that to the php page. However i am very new to javascript and not sure if it is possible.
Any suggestions would be appreciated below is my javascript code, thanks.
var track = new Image();
track.src="http://testsite.co.uk/~vtrack/track/track.php?id=801003&self=" + document.referrer;
track.src = "http://testsite.co.uk/~vtrack/track/track.php?id=801003" +
"&self=" + document.referrer +
"&pageTitle=" + document.title;
document.title = `Your Title goes here`
Related
I have a javascript code which shows all the urls in a textarea / textbox. I would like to show the web title of those urls. But I don't want to load the whole website (get_content) as it manipulates the other javascripts on my page. How can I show the title?
My Code
<script>
let result = $("#converted_url");
$("#textarea_input").on("input", function() {
result.html("");
var urlRegex = /(?:(?:http|https):\/\/)?([-a-zA-Z0-9.]{2,256}\.[a-z]{2,4})\b(?:\/[-a-zA-Z0-9#:%_\+.~#?&//=]*)?/gi;
var found = [];
$("#textarea_input").val().replace(urlRegex, function(url) {
let trimmedUrl = url.replace(/^(?:https?:\/\/)?(?:www\.)?/i, "");
if (found.includes(trimmedUrl)) {
return;
}
found.push(trimmedUrl);
var link = '<a target="_blank" href="' + url + '">' + TITLE + '</a>';
result.append(link);
});
});
</script>
Should output something like this:
Simply put: you can't. The title of a webpage is only stored in its HTML content, so without downloading that content, you can't get the title. I don't understand what you mean by "it manipulates the Javascripts on my page" -- if you make an AJAX call to the URL you want (assuming it's same-domain or has CORS enabled), you'll get back the raw source code as a string to parse as you wish, and it won't affect anything else on your page.
I was hoping somebody could please assist on a problem I am currently having. I have an IFrame named IFrame1 implemented on a client website. On the client website they have certain information of the user in the QueryString for instance clientwebsite.com/login.aspx?UserID=xxxx&UserName=xxxx.
Using MVC what would be the best way of retrieving the entire querystring while I only have an IFrame on the website?
I tried using JavaScript to retrieve the window.location but this only displays the URL where my IFrame is deployed (MyServer.com) and not where it has been implemented(clientwebsite.com). I also tried using C# HttpRequest.QueryString. This also just displays the URL where my solution was deployed and not the client website URL.
If anybody has any suggestions it would be greatly appreciated.
EDIT
I tried using the window.parent.location as many suggest. I wrote a small webpage where I just pull the code and display it as follows :
<script type="text/javascript">
document.write("window.location.href : " + window.location.href + "<br />");
document.write("window.parent.location : " + window.parent.location + "<br />");
document.write("document.referrer : " + document.referrer + "<br />");
</script>
When I run this page I get the result as follows :
window.location.href http://mywebsite.com/test
window.parent.location http://mywebsite.com/test
document.referrer
Which is fine but when I view this through the clientwebsite it onlyu displays the href value but neither the window.parent.location label or the value. Can this be caused due to permissions?
You should try using :
var parentUrl = window.parent.location;
window.parent will get you inside the parent window and then you can do anything with the parent window.
Hi Ruben,
I believe you need to add window.parent.location.search . You can do something like this for query string. This answer was provided by Marwan:
function getQueryString() {
var queryStringKeyValue = window.parent.location.search.replace('?', '').split('&');
var qsJsonObject = {};
if (queryStringKeyValue != '') {
for (i = 0; i < queryStringKeyValue.length; i++) {
qsJsonObject[queryStringKeyValue[i].split('=')[0]] = queryStringKeyValue[i].split('=')[1];
}
}
return qsJsonObject;
}
Just call it from the child window like this and act with the query string as an object.
For example if you have the query string ?name=stack and you want to get it, try:
getQueryString().name
This will return stack.
<script type="text/javascript">
var email = document.write(localStorage.getItem('email'));
var pass = document.write(localStorage.getItem('pass'));
var url = document.write(document.URL);
document.location.href = url+"?email="+email+"&pass="+pass;
</script>
But when I enter the page I left the url like this:
http://example.com/undefined?email=undefined&pass=undefined
Not happening ... Anyone know the problem? Thank you very much!
Well, what's up with document.write(…) in here? You don't want to print out anything:
var email = localStorage.getItem('email');
But if you want to print out the values for testing:
var email = localStorage.getItem('email');
document.write(email);
(See also console.log(…))
You should escape the parameters using encodeURIComponent(…):
location.href = url + "?email=" + encodeURIComponent(email) +
"&pass=" + encodeURIComponent(pass);
Also you should not use document.write anyhow. There are plenty more reasonable methods to change the content dynamically on you website.
You should not send a password using GET requests, as they will appear the browser, proxy and server logs. Use POST requests through invisible forms.
Am trying to create a link to create an email to send information to the user, the body of which needs to be filled with data generated by a javascript function, and hope that someone can help.
Idealy, if I could substitute the 'body_blurb' below, with a string returned from a javascript function called at the time of clicking that'd be perfect.
e-mail data
Appreciate your time
I just assigned an id to the link here, but you could create something more generic if you wanted. Once you have an onclick handler created you can access the url with href. Set this to whatever you want.
http://jsfiddle.net/f3ZZL/1
var link = document.getElementById('email');
link.onclick = function() {
this.href = "mailto:you#yourdomain.com?subject=Data&body=";
this.href += getBody();
};
function getBody() {
return 'HelloWorld';
}
Here is the no-spam method
var link = document.getElementById('email');
link.onclick = function() {
var name = "you";
var domain = "yourdomain.com";
var linker = "mailto:" + name + '#' + domain + "?subject=Data&body=";
linker += getBody();
link.setAttribute("href", linker);
};
function getBody() {
return 'HelloWorld';
}
On Fiddle
You don't actually need to set the href value. What you're really trying to do is send the browser to a mailto: URL: the href is just a means to that end.
Leave the href blank and make the link have an onClick handler. In the onClick, feed the browser the mailto: URL (after you build it using your variable). Presto, done.
I am trying to set a href of a tag using java script for making that tag open a dialog to send a mail.
var ancHref = "mailto:abc#abc.com "?"subject=Blank filter"+" "+'<%=QWebUtility.GetAppSettings().GetSetting("CompanyName") %>';
$("#divMessageBody").append("<a href=" + ancHref + "/>");
but something is going wrong can you tell me how to append a subject that could be dynamic in nature that i am doing.
Yours variable is wrong:
var ancHref = "mailto:abc#abc.com?subject=Blank filter"+'<%=QWebUtility.GetAppSettings().GetSetting("CompanyName") %>';
$("#divMessageBody").append("<a href=" + ancHref + "/>");
You typed too much "
one question is: are you doing this script externally or within the page? by your example, i think you are on the page. try changing to this
var ancHref = 'mailto:abc#abc.com?subject=Blank filter <%=QWebUtility.GetAppSettings().GetSetting("CompanyName") %>';
try this method of creating an element also:
var ancHref = 'mailto:abc#abc.com?subject=Blank filter <%=QWebUtility.GetAppSettings().GetSetting("CompanyName") %>';
var mylink = $(document.createElement('a'));
mylink.attr('href',anchref);
$("#divMessageBody").append(mylink);