Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create embed code for other sites

I have a service of job portal which other users can use for their sites and blogs. they copy embed code from my site, paste it in their site and display job board in their webpage. how create this embed code anyone can help me.

Here is example monster.com publisher website.

click Get sample code button.

<div id="MonsterJobSearchResultPlaceHolderIy8AAA_e_e" class="xmns_distroph"></div>
<script type="text/javascript">
(function() {
  var oScript = document.createElement('script');
  oScript.type = 'text/javascript';
  oScript.async = true;
  oScript.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'publisher.monster.com/Services/WidgetHandler.ashx?WidgetID=EAAQgDMlA5vzabXFzuv86ZpLpA--&Verb=Initialize';
  var oParent = document.getElementsByTagName('script')[0];
  oParent.parentNode.insertBefore(oScript, oParent);
})();
</script>
<a id="monsterBrowseLinkIy8AAA_e_e" class="monsterBrowseLink fnt4" href="http://jobsearch.monster.com/browse/">View More Job Search Results</a>
like image 982
Nand Lal Avatar asked Dec 31 '12 07:12

Nand Lal


2 Answers

there are many ways to reach your goal. As you didn't explain your need explicitly, I just provide a simple example:

<script type='text/javascript' charset='utf-8'>         var iframe = document.createElement('iframe');           document.body.appendChild(iframe);     iframe.src = 'URL OF CONTENT YOU WANT TO PROVIDE';           iframe.width = 'THE WIDTH YOU WANT';    iframe.height = 'THE HEIGHT YOU WANT'; </script> 
  1. modify the code according to your need
  2. escape this code in your html
  3. have fun with your awesome embedded widget!
like image 123
Brian Avatar answered Sep 23 '22 17:09

Brian


How To Create Embed With Javascript in .cs

Note: localhost:3197/website/js/embed/form.js'; // give your js path

FormBuilder(921,'MjEzNjkxMjU='); in this method first parameter give your form height and second your form name or Id. there Id is encoded format

StringBuilder sb = new StringBuilder();     sb.Append("<script type='text/javascript'>");     sb.Append("(function(d, t) { var s = d.createElement(t), options = {");     sb.Append("'async':true };");     sb.Append("s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'localhost:3197/website/js/embed/form.js';");     sb.Append("s.onload = s.onreadystatechange = function() {");     sb.Append("var rs = this.readyState; if (rs) if (rs != 'complete') if (rs != 'loaded') return;");     sb.Append("try { frm = new FormBuilder("+Form Height+",'"+FormId+"');frm.initialize(options);frm.display(); }");     sb.Append("catch (e) {}};");     sb.Append("var scr = d.getElementsByTagName(t)[0], par = scr.parentNode; par.insertBefore(s, scr);");     sb.Append("})(document, 'script');</script>");      txtjavascript.Value = sb.ToString();  // text box name 

After Create embed script Simple and Easy Way Paste this script where you want to show in other page after that

(function(d, t) { var s = d.createElement(t), options = {'async':true }; s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'localhost:3197/website/js/embed/form.js'; s.onload = s.onreadystatechange = function() {var rs = this.readyState; if (rs) if (rs != 'complete') if (rs != 'loaded') return; try { frm = new FormBuilder(921,'MjEzNjkxMjU='); frm.initialize(options); frm.display(); }catch (e) {}}; var scr = d.getElementsByTagName(t)[0], par = scr.parentNode; par.insertBefore(s, scr);})(document, 'script');

After That in your js file Create fuction like this and create iFrame ans create querystring where you fetch the form from database.

function FormBuilder(fHeight, formid) {      var iframe = document.createElement('iframe');     iframe.style = "height:" + fHeight + "px; width:100%; border:none";     iframe.setAttribute('allowTransparency', true);     iframe.frameBorder = "0";     iframe.scrolling = "no";     iframe.src = "http://localhost:3197/form/show-form?id="+ formid;     document.body.appendChild(iframe); } 
like image 24
gaurav gupta Avatar answered Sep 22 '22 17:09

gaurav gupta