Assuming an HTML web form with 2 hidden fields.
landingurl: the full url where the visitor landed before submitting the form including tracking codes
referealurl: the full referal url (where the visitor came from)
I want to jquery to save those values in the value fields which are hidden in the form.
I can't figure it out
You can grab the current URL with window.location.href, so if you grab the href on the landing page, then you have the landing URL.
You can grab the referring URL with document.referrer. This also needs to be grabbed on the landing page.
I haven't used jQuery in a while, but I believe the syntax would be something like this:
// For this example I have assumed your fields have the IDs landingURL and referralURL.
$('#landingURL').val(window.location.href);
$('#referralURL').val(document.referrer);
Now, if the landing page is not the same page as the form, and you need to pass this information along to the form page using only JavaScript in the browser, then I would suggest that you grab the landing page URL and the referral URL as described above and save them in either localStorage or sessionStorage.
Here's an example of how you can do that:
// On the landing page:
localStorage.setItem('landingURL', window.location.href);
localStorage.setItem('referralURL', document.referrer);
// On the form page:
$('#landingURL').val(localStorage.getItem('landingURL'));
$('#referralURL').val(localStorage.getItem('referralURL'));
Hope that helps!
Related
Actually, I am using advance custom field plugin and I have made a repeater with three fields language, release and download (file type).
So now I have made a custom template for every post and retrieved repeater fields on it so I want that when user will click on download button then it will redirect on another page with a custom URL with post name and language both.
I need post name and language into that link then on final page
I will give the download option. Below are pages link of the post
https://subtitlesrt.com/movie-imdb/fifty-shades-freed-2018-arabic-subtitles-download-srt-%D8%AA%D8%B1%D8%AC%D9%85%D8%A9-%D8%A7%D9%81%D9%84%D8%A7%D9%85/
I have also set download page on custom page.
Let me know the right solution for it.
If i were you i would follow these steps.
Create a new page with name of Custom download maybe
create a custom template for that page
in your posts when you show repeater values, use the values like a form with GET method (maybe input types can be hidden for aesthetic) and submit the form to this new page.
In this page you can get the repeater field values with form and do whatever you want.
NOTE: i suggested GET method because you said "... it will redirect on other page with a custom url .." GET method show values in url and you can index them.
I have a simple html form which contain 2 fields and submit button. After hitting submit button my data transfer toward the another server through query string named "http://www.123contactform.com" which is load in iframe on my page and the field which is in the iframe become pre-populated with the information coming from query string. That's All I have done.
Now what I want want when the submit button of iframe click, the page transfer towards the another page, I want to restrict that navigation and define my own url with javascript.
Can any one help me, How do I get this???
Regards,
Ammar
Can you show some code ?
And
Logically What you want is something like this - You have an iframe on example.com and that iframe load's gmail's login page, You want to change the submit url of gmail's login form ?
NOT POSSIBLE
How would you go about inserting an OnSubmit attribute to a form via Javascript only?
I'm pretty new to javascript so if you're able to provide detailed example code, that would be most helpful!
Here's the situation: I'm using a hosted signup page through Chargify (a payments platform) in order to process credit cards for my app, and then send the user back to my own thank you/confirmation page.
Tracking the entire funnel through google analytics is proving quite elusive due to changing domains (my domain -> Chargify.com -> my domain), since the credit card page is hosted by Chargify on their own domain.
I'm getting close: I've been able to get cross-domain tracking working (chargify.com page gets logged in Google Analytics), and can link from my domain to chargify by adding the following onclick attribute to my signup link:
onclick="_gaq.push(['_link', 'http://my-domain.chargify.com/subscriptions/new']); return false;"
However, I cannot do the same thing on the way back (Chargify -> Confirmation page) because I do not have access to the Chargify hosted payment page code, and because the user is taken to my confirmation page via a form submission, not a normal link.
Partial Solutions (need your help to finish this up):
Chargify allows several options for their hosted pages, one of them being to add custom javascript that gets inserted right before the </body> tag in a <script> tag.
I found some resources in the Google Analytics documentation on how to link pages, and adding the following to the Chargify form tag might work: onsubmit="_gaq.push(['_linkByPost', this]);"
(source: https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiDomainDirectory#_gat.GA_Tracker_._linkByPost)
The form tag does not currently have an onsubmit attribute, it's just this: <form action="/my_product/subscriptions" class="new_submission" id="hosted_payment_form" method="post">
Is there a way to use Javascript to simply append this attribute to the form tag? If you'd be able to provide a detailed example of what code I should insert inside of the <script> tag, that would be extremely appreciated.
window.onload = function() {
var form = document.getElementById('hosted_payment_form');
form.onsubmit = function() {
_gaq.push(['_linkByPost', this]);
}
}
I believe the above example is similar to what you need. We use document.getElementById to grab a reference to your form. Then set the onsubmit property to the code you want executed before the form is submitted. Remember to put this inside the window onload event if this JavaScript is executed before the page is rendered to ensure the form is built.
So, I want to change the display style of one of my divs, here's the code in my javascript:
document.getElementById("header1").style.display='none';
Now the problem... header1 is a div id on a different page, but I want to affect that from selecting an option on the current page. How do I go about doing that so that the header1 will be hidden when I go onto the next page?
Thank you in advance!
You cannot change the properties of an element that has not been loaded into the browser yet. You would have to use a cookie or the querystring to tell you to hide the element when the page is loaded.
Edit
You can redirect to a new page using the following javascript. Note: everything following the ? is part of the querystring.
// Redirect without querystring
window.location = "http://www.mySite.com/default.html"
// Redirect with querystring
window.location = "http://www.mySite.com/default.html?hide=true"
// Redirect with multiple values in querystring
window.location = "http://www.mySite.com/default.html?hide=true&test=1"
Check out get-query-string-values-in-javascript to see how to retrieve querystring values through javascript.
You could pass the value to the next page in a hidden form field or possibly via the url then when that page loads use that value to set the desired value on the page.
how about carrying the value/selection to the other page using local/session storage, or even indexDB, if you have a lot of information to carry or you are carrying across multiple pages. saves having unneeded POSTS and removes the need for any server side code
I have a page where there is a form(and url is xyz.com/form)...
Now when the user submits the data, it should redirect to the home page of xyz.com(url is xyz.com) and then display a message as "Thank you" in an existing div id (div id="message")of the home page...
Is it possible to do it using javascript??
Will I get the value of that div id(message) when the it redirects to home page using javascript.
I could redirect the page to home page.. but couldnt insert contents in that div... or in a new div...
Please help
i would add a GET-parameter to the url like "status=ok". on the main-page you can check this parameter with javascript and change the value ('innerHTML') of the div.
Without having seen your code, i would say yes, it is possible.
On entering the main page you can check the referring page and you could also check some session stored data that validates if the user has submitted the form (i suggest ajax for this).