How do I send a parameter to an iframe on another page? - wordpress

I'm trying to integrate TrackerRMS on my WORDPRESS website. On the main jobs page, I have an iframe that produces a listing of jobs.
<iframe frameborder="0"
scrolling="yes"
width="1000"
height="780"
src="https://evoportalus.tracker-rms.com/mycompany/jobs?
theme=purplehaze
&fields=title,worktype,location,salaryfrom,salaryto,sector,joblink
&joblinkuri=http://example.com/jobs-detail&joblinktarget=_parent&filters=">
</iframe>
Once displayed, there is a button on the page with a link to apply for that job is in this format:
http://example.com/jobs-detail?jobcode=1234
The problem is that I need to be able to pass the number, 1234, into this iframe code, on the jobs-detail page.
<iframe frameborder="0"
scrolling="no"
width="100%"
height="700"
src="https://evoportalus.tracker-rms.com/mycompany/jobs
?theme=purplehaze
&fields=reference,title,location,worktype,description,linkregister
&filters=reference|JOBCODE-NUMBER-NEEDS TO APPEAR HERE">
</iframe>
What do I need to add to the second iframe code on the jobs-detail page to grab the jobcode number from the URL, and append it after the "reference|"?
Note again, this is a Wordpress site, so I'm just using a shortcode to insert raw HTML code onto the page.
Thank you.

Apparently this works, by adding this code to the jobs-detail page:
<script type="text/javascript">
loadSite();
function getQueryString (field, url) {
var href = url ? url : window.location.href;
var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
var string = reg.exec(href);
return string ? string[1] : null;
};
function loadSite() {
var site = "https://evoportalus.tracker-rms.com/mycompany/jobs";
site += "?theme=purplehaze&fields=reference,title,location,worktype,description,linkregister&filters=reference|" + getQueryString("jobcode");
console.log(site);
document.getElementById('trmsjobs').src = site;
}

Related

WordPress youtube iframe not working after change content output function in post

I have changed in theme file to display post output like below but now if am going to add any youtube URL in post text it is not showing video iframe. also, I can not use the_content() function because there is some other issue with that function.
//the_content();
$post_content .= $post->post_content;
echo $post_content;
can anyone help me to show the iframe if I add the youtube video URL in the post and display the iframe in the frontend? I know this is default WordPress functionality but it is not working.
any solution will be fine if there is a jQuery function also fine.
So, if I've understood correctly, that you can add content to a post and it shows in front end but that youtube url does not display correctly in an iframe (so it's an oembed problem) then it might make sense to think about adding the whole embed code from YouTube.
Instead of pasting https://youtu.be/TE66McLMMEw into your content area, you might paste in this instead:
<iframe width="560" height="315" src="https://www.youtube.com/embed/TE66McLMMEw" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
There are ways of using JS, grabbing a YouTube url and dynamically generating an iframe for it using the YouTube Player API (as per the video, or full docs and examples here: https://developers.google.com/youtube/iframe_api_reference ) but honestly, it seems a very complex way to solve the problem. It might be better to try and find a more robust fix that lets you use the_content().
UPDATE: if you cannot use iframe directly
We can use notes from youtube API (and a great regex from this answer here: https://stackoverflow.com/a/8260383/8228720) to generate iframe on the fly. You just need to create a div with id "player" and paste the YT url inside it.
HTML
<div id="player">https://youtube-video-link-goes-here</div>
JS
//Get video url from div
let videoUrl = document.getElementById("player").textContent;
let videoId = youtube_parser(videoUrl);
var tag = document.createElement('script');
//Parse url for video id
function youtube_parser(url){
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
var match = url.match(regExp);
return (match&&match[7].length==11)? match[7] : false;
}
//Dynamically create iframe in the "player" div, adding our video id to it.
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: videoId,
playerVars: {
'playsinline': 1
},
});
}

Pull URL parameters into a WordPress "Raw HTML" content element

I'm using the URL Params plugin to pull parameters into regular content using a short code. But I have to use a Raw HTML block to insert Typeform code into the page and I want to be able to pass a URL parameter into the Typeform code to track the source of the form submission.
I can't figure out how to do it. The form is working fine at: https://HelloExit.com/instant-valuation
But I want to be able to send people to https://HelloExit.com/instant-valuation/?source=XXXX and pull the XXXX into the Typeform code as the "source" value in the "data-url"
Here's what I tried:
<script>
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
var source = getUrlVars()["source"];
</script>
<div
class="typeform-widget"
data-url="https://xgenius.typeform.com/to/zZHPPk?source=<script>document.write(source)</script>"
data-transparency="100"
data-hide-headers=true
data-hide-footer=true
style="width: 100%; height: 500px;">
</div>
<!-- Typeform embed code -->
<script>(function() { var qs,js,q,s,d=document, gi=d.getElementById,
ce=d.createElement, gt=d.getElementsByTagName, id="typef_orm",
b="https://embed.typeform.com/"; if(!gi.call(d,id)) { js=ce.call(d,"script"); js.id=id;
js.src=b+"embed.js"; q=gt.call(d,"script")[0]; q.parentNode.insertBefore(js,q) } })()
</script><div style="font-family: Sans-Serif;font-size: 12px;color: #999;opacity: 0.5;padding-top: 5px;"> powered by Typeform</div>
Any assistance would be greatly appreciated!
You're close, but you'll need to use Javascript to alter the data-url attribute of your div.
// ...
var source = getUrlVars()["source"];
// concatenate the url with your source variable
var newUrl = `https://xgenius.typeform.com/to/zZHPPk?source=${source}`;
// get the element whose attributes you want to dynamically set
// https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
var widgetElement = document.querySelector('.typeform-widget');
// set the source attribute
// https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute
widgetElement.setAttribute('data-url', newUrl);
Test this carefully, as it might still end up with a race condition (that is, the Typeform embed code might start running before you've updated the data-url attribute that it references).

Redirect Blogger custom domain posts to another domain

I have a blogger blog on http://blog.example.com and I've moved the blog to a new site using WordPress and set up redirects inside WordPress to redirect blogger posts URLs to new URLs for example:
the post on blogger is: http://blog.example.com/2016/12/google.html
the post URL on the new site is: https://subdomain.domain.com/google/
I've set redirects inside WordPress to redirect from https://subdomain.domain.com/2016/12/google.html TO https://subdomain.domain.com/google/
So all what I want is a code to add in the old blogger blog to redirect each page to another page in the new domain, for example:
Redirects from: http://blog.example.com/2016/12/google.html TO https://subdomain.domain.com/2016/12/google.html
and http://blog.example.com/2015/11/yahoo.html TO https://subdomain.domain.com/2015/11/yahoo.html
Thanks in Advance!
Locate the tag in the header section and insert the following code after the tag: http://www.yoursite.com/'" /> Replace "http://www.yoursite.com" with the URL of the website to which you want to redirect your blog.
Original article
Switch from compose to HTML in your post edit and put this code inside the post body.
<script type="text/javascript">
window.location = 'http://your-external-link';
</script>
Actually it's the first time I publish a JavaScript but I'm open to suggestion,edit,comments ...
The idea is to put the following script in blogger template so it'll redirect automatically the user.
Do not forget to change the variables googleBaseURL and wordpressBaseURL.
<script type="text/javascript">
var googleBaseURL = 'http://blog.example.com/', // We define what's our blogger URL
wordpressBaseURL = 'https://subdomain.domain.com/', // We define what's our wordpress URL
requestedURL = window.location.href, // We get the URL requested by the user
requestedPage = requestedURL.split(googleBase)[1], // We get the requested page
newURL = wordpressBase + requestedPage; // We create our new URL
window.location = newURL; // We redirect
</script>
Here's a snippets which resume your explanation.
var div = document.getElementById('message'),
googleBaseURL = 'http://blog.example.com/', // We define what's our blogger URL
wordpressBaseURL = 'https://subdomain.domain.com/', // We define what's our wordpress URL
requested = 'http://blog.example.com/2016/12/google.html', // URL requested by user
requestedPage = requested.split(googleBaseURL)[1]; // Requested page by user
div.innerHTML = div.innerHTML + "From: " + requested + "<br />"; // Requested url
div.innerHTML = div.innerHTML + "The script redirect the user to: " + wordpressBaseURL + requestedPage; // Redirect to this url
<div id=message></div>
Insert the code shown below just after the “” tag in the blogger template after replacing the generalized content to your own in the code below.
<b:if cond="’data:blog.url" =="“http://your-blog-name.blogspot.com/YEAR/MONTH/BLOG-POST-SLUG.html”‘"><meta content="’0;url=http://yoursite.com/NEW-BLOG-POST-SLUG.html’" http-equiv="’refresh’/"></b:if>
Source

How can I pass UTM parameters from URL to an iframe?

i have a link google adword :
http://example.com?utm_campaign=Testcam&utm_medium=referral&utm_source=Blog&utm_content=blogers&utm_term=Test
When visitor click the link above to navigate to mysite. And then he submit a Marketo form (non Marketo form for landing page on my site).
I follow this article to create Mkto form on my site: http://community.marketo.com/MarketoResource?id=kA650000000GsPJCA0 to make sure when it submit it will get values from url parameters.
My problem on here is : Normally, this form just submit to the server to handle register. Beside that, when this form submmited, i also need it submit to Marketo for tracking. That a reason, Marketo form will be submit via iframe.
When i submit marketo form, it will be target to this iframe.
So, i need pass the url parameter into iframe to make sure when submit form, hidden fields will automatic get values from url parameters. But on this iframe, as you can see, it haven't src. I had try to add this to iframe:
$("#mktoformhidden").src = window.location.href;
but it doesn't work well.
What's the iframe src should be on here?
Thanks,
I would do something like this! Just replace "URL HERE" with your iframe url and of course update the sizing that you need in BOTH loactions.
<noscript>
<iframe src="YOUR URL HERE" width="100%" height="500" type="text/html" frameborder="0" allowTransparency="true" style="border: 0"></iframe>
</noscript>
<script type="text/javascript">
var iframeurl = 'YOUR URL HERE';
var params = window.location.search;
var thisScript = document.scripts[document.scripts.length - 1];
var iframe = document.createElement('iframe');
iframe.setAttribute('src', iframeurl + params);
iframe.setAttribute('width', '100%');
iframe.setAttribute('height', 500);
iframe.setAttribute('type', 'text/html');
iframe.setAttribute('frameborder', 0);
iframe.setAttribute('allowTransparency', 'true');
iframe.style.border = '0';
thisScript.parentElement.replaceChild(iframe, thisScript);
</script>
My guess is that an iframe is not the best solution here. The iframe can create all sorts of cross site scripting and permission based concerns.
Why not just use the new forms functionality in Marketo so you can drop the form either on a landing page or embed on your site (they come with an embed source code).
Also, the munchkin tracking code automatically grabs "query" parameters so you can use those in smart lists or reporting.
Like sahutchi said, embedding the actual Marketo form into your site could be the way to go. I opted for the iframe approach to get Marketo to automatically fill in fields based on mkt_tok. This might be possible using Marketo forms, but I wasn't able to figure it out a month or two ago.
Here's a decent overview of ways that you can integrate Marketo forms with your site: http://www.elixiter.com/marketo-landing-page-and-form-hosting-options/
If you insist on doing it the iframe way, here's my setup to pass query string params down to the embedded iframe:
This is in http://yourdomain.com/my-marketo-page:
<div class="lazy-iframe" data-src="//pages.yourdomain.com/MyMarketoPage.html" style="width: 960px; height: 1000px;">
</div>
And in some shared library (but you can have it on the same page, and simplify it a bit):
<script>
$(function() {
var $lazyIframe = $('.lazy-iframe');
if ($lazyIframe.length) {
var src = $lazyIframe.attr('data-src');
if (src) {
var $iframe = $('<iframe src="' + src + location.search + '"></iframe>');
$iframe.attr({
scrolling: 'no',
frameborder: 0
});
$lazyIframe.replaceWith($iframe);
}
}
});
</script>
Given that pages.yourdomain.com is your CNAME to your Marketo domain.
In my email, I just link to http://yourdomain.com/my-marketo-page, and Marketo will automatically add the mkt_tok for that email recipient to the end of that URL (becoming http://yourdomain.com/my-marketo-page?mkt_tok=BLAHBLAHBLAH). Then the iframe is constructed with the data-src URL and all of the parameters attached, and with no scrolling nor frameborder (up to you).

Pass through '&parameter' in a URL

I'm working on a project which passes a variable into a iFrame with this code:
jQuery(function() {
var search = window.location.search;
jQuery(".iframe-wrapper").attr("src", jQuery(".iframe-wrapper").attr("src")+search);
});
But, when I pass through &section=P1 in a URL, it just gives a 404.
Source of the iFrame: example.com/page?cart=1
After going to site.com/&section=P1 the iFrame should change to example.com/page?cart=1&section=P1
Anyway to pass through the &section=P1 through the URL?
Please send your HTML as mine is working fine with the below:
<iframe width="500" height="200" class="iframe-wrapper" src="http://www.google.com?param=1"></iframe>
<script type="text/javascript">
$(function() {
var search = window.location.search;
search = search.replace("?","&");
$(".iframe-wrapper").attr("src", $(".iframe-wrapper").attr("src")+search);
});
</script>

Resources