javascript - Grab referrer to parent in iFrame (different domain) form hidden field -
i loading form in iframe using javascript , adding referrer url pass parameter iframe (step 1) populating hidden field on form (step 2).
step 1 works fine , yields similar this:
http://www.parentdomain.com/parentpage/?refurl=http://www.somereferringurl.com/somerefpage/
step 2 (where getting stuck)
function gup( grabref ) { grabref = grabref.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexs = "[\\?&]"+grabref+"=([^&#]*)"; var regex = new regexp( regexs ); var results = regex.exec( window.location.href ); if( results == null ) return ""; else return results[1]; } var referrer = gup( 'refurl' ); function start() { var ref = document.getelementbyid('my-formfield-id');{ ref.value = referrer; } onload = start; }
this (still) seems yielding parent referrer (http://www.parentdomain.com/parentpage/), , (in fact) seems appending url string closing tag. form , parent reisde in different sub-domains. guessing culprit may lye here: ref.value = referrer;
any ideas?
i unable work resorted grabbing iframe parent referrer , changing parent page (and embedding same form in iframe) capture different campaign referr urls needed. can still grab them in 1 location using same form, have been nice have 1 parent (landing page) , pass along referrer parent.
this code that:
<script type="text/javascript"> function getparameterbyname(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new regexp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeuricomponent(results[1].replace(/\+/g, " ")); } var refval = getparameterbyname('refurl'); //document.write(refval); function setvalue() { document.getelementbyid('my_hidden_formfield_id').value = refval; //alert(document.getelementbyid('my_hidden_formfield_id').value); } </script>
thanks looking.
Comments
Post a Comment