Is it possible to write redirect script by using referrer url and get div element? Something like below:
Referrer is - sitename.com/example/#bang1#bang2#bang3
Redirect site - a href="http://anothersite.com/"id="redirectthis">Redirect this
Tried -
<script>
var separator1 = (document.referrer.indexOf('[tag]') !== 1)
var separator2 = (document.referrer.indexOf('[tag]') !== 2)
var separator3 = (document.referrer.indexOf('[tag]') !== 3)
var relocate = document.write(document.getElementById("redirectthis") + separator1 + separator3 + separator2);
window.location = relocate
</script>
Result wanted - This would lead a redirect to http://anothersite.com/bang1/bang3/bang2
Related
I found this google translate bookmarklet from here and I was wondering if it was possible to run this code in an iframe, on the same page, instead of a new window.
javascript: var t = ((window.getSelection && window.getSelection()) || (document.getSelection && document.getSelection()) || (document.selection && document.selection.createRange && document.selection.createRange().text));
var e = (document.charset || document.characterSet);
if (t != '') {
var url1 = 'http://translate.google.com/?text=' + t + '&hl=en&langpair=auto|sk&tbb=1&ie=' + e;
window.open(url1, '_blank', "GoogleTranslate", "height=200,width=200")
} else {
var url2 = 'http://translate.google.com/translate?u=' + encodeURIComponent(location.href) + '&hl=en&langpair=auto|sk&tbb=1&ie=' + e;
window.open(url2, '_blank', "GoogleTranslate", "height=200,width=200")
};
void(0);
NO, it's not possible.
Google made it impossible because they did not include the X-Frame-Options header in the urls included in the script you provided, which is essential for displaying the requested url content in an iframe.
You can check an example here: https://jsfiddle.net/5w2tv8fs/
You can notice in console a message that the request is refused because the header is missing.
I want two types of domain redirects on the same site (if else statement etc):
If user has cookie:
And url subdomain is amazon then redirect to url xxxxxx
And url subdomain is ebay then redirect to url xxxx
If user has no cookie:
And url subdomain amazon then first forward to ebay subdomain and back to amazon subdomain once (currently creates a loop) and display background xxxx with href link xxxx
And url subdomain ebay then first forward to amazon subdomain and back to ebay subdomain once (currently creates a loop) and display background xxxx with href link xxxx
Synchronise user cross-domain click for a new pop-up for href xxxxx - ie if user has come on site by clicking on link on another site then see asynchronise click to open another pop-up (200 sec rule)
Currently site already has below which I still need, so cookie redirect shouldn't set a redirect to site outside because of the code below but only if user is genuinely a returning user
var subdomain = window.location.hostname.split('.')[0];
if (!document.cookie == null && subdomain === "amazon") {
window.location = "http://www..com";
} else if (!document.cookie == null && subdomain === "ebay") {
window.location = "http://www.tutorialspoint.com";
} else if (document.cookie == null && subdomain === "amazon") {
var oLinksArray = [];
oLinksArray[0] = 'http://www.ebay.com';
oLinksArray[1] = 'http://www.amazon.com';
for (var x = 0; x < 2; x++) {
var openWindow = window.open(oLinksArray[x]);
setTimeout(function() {
openWindow.close();
}, 2000);
}
} else if (document.cookie == null && subdomain === "ebay") {
var oLinksArray = [];
oLinksArray[0] = 'http://www.amazon.com';
oLinksArray[1] = 'http://www.ebay.com';
for (var x = 0; x < 2; x++) {
var openWindow = window.open(oLinksArray[x]);
setTimeout(function() {
openWindow.close();
}, 2000);
}
} else {}
You don't need to transfer cookie with redirection. Cookie has a property called domain. You should add website's domains to give access permission to them.
In Javascript
var cookieName = 'HelloWorld';
var cookieValue = 'HelloWorld';
var myDate = new Date();
myDate.setMonth(myDate.getMonth() + 12);
document.cookie = cookieName +"=" + cookieValue + ";expires=" + myDate
+ ";domain=firstDomain.com,nextDomain.com;path=/";
In PHP
setcookie('mycookie','mydata1',time() + 2*7*24*60*60,'/','www.firstDomain.com,nextDomain.com', false);
On my razor view, I am wanting to put all of my jQuery into a separate JS file and then reference that file on the view with #Scripts.Render.
On my view, I have a section jQuery that looks like this:
var settings = {};
settings.baseUri = '#Request.ApplicationPath';
var submissionUrl = "";
if (settings.baseUri === "/ProjectNameOnServer") {
submissionUrl = settings.baseUri + "/api/apiControllerName/apiControllerMethodName/";
} else {
submissionUrl = settings.baseUri + "api/apiControllerName/apiControllerMethodName/";
}
This section of code allows me to test submitting forms with api on both my localhost and live on the server without me having to change the url.
If I am testing on my localhost, then #Request.ApplicationPath == /, but if I test on my server then #Request.ApplicationPath == /ProjectNameOnServer.
I was wondering how I could achieve getting these same values but without the use of Razor, and instead only with jQuery.
I have tried:
var settings = {};
settings.baseUri = window.location.protocol + "//" + window.location.host;
but then settings.baseUri == http://localhost:xxxxx. I just need exactly what #Request.ApplicationPath is giving me.
Use location.host to conditionally create relative path
settings.baseUri = location.host.includes('localhost') ? '/' : '/ProjectNameOnServer';
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 have 2 files, there are Index.aspx and AdminHome.aspx. and also have javascript file (test.js) for logic behind.
Index and adminHome is actually same but the different is only the redirect action.
If I run program from Index.aspx then i'll be redirect to CheckSeat.aspx
If I run program from AdminHome.aspx then I'll be redirect to AdminCheckSeat.aspx. I want to use same Javascript because each file has same logic. only the redirect file is the different.
this is my redirect code on .js
var url = "CheckSeat.aspx?noSeat=" + encodeURIComponent(lObjSeat[0].Name) + "&endtime=" + encodeURIComponent(time);
window.location.replace(url);
so Is it possible to do ?
if ya, How do you do ?
example URL : http://localhost90909/abcd/index.aspx
I need 'index.aspx' segment only
You may replace the url based on current page.
if (document.URL = 'Index.aspx') {
var url = "CheckSeat.aspx?noSeat=" + encodeURIComponent(lObjSeat[0].Name) + "&endtime=" + encodeURIComponent(time);
window.location.replace(url);
}
else if (document.URL = 'AdminHome.aspx') {
var url = "AdminCheckSeat.aspx"
window.location.replace(url);
}