Friday, April 7, 2017

Defining a HTML template to append using JQuery

Append Dynamic content to html template using Jquery

If we want to append the dynamic content to html template using jquery below will be the simple solution

Wednesday, April 5, 2017

Iframe communication or Accessing a cross-origin frame

Accessing a cross-origin frame.

window.postMessage allows you to send messages not only across frames (regular frame or iframe) but also across domains. This post showed interaction from parent to child. Even when we keep the iframe domain url is different for the main page url.
With out using the window.postMessage will gives us below error message in console

SecurityError: Blocked a frame with origin from accessing a cross-origin frame

You can't access an iframe with Javascript, it would be a huge security flaw if you could do it.
For the same-origin policy browsers block scripts trying to access a frame with a different origin.
Origin is considered different if at least one of the following parts of the address isn't maintained: ://:/path/to/page.html Protocol, hostname and port must be the same of your domain, if you want to access a frame.


Examples
Here's what would happen trying to access the following URLs from http://www.example.com/home/index.html

URL RESULT
http://www.example.com/home/other.html -> Success
http://www.example.com/dir/inner/another.php -> Success
http://www.example.com:80 -> Success (default port for HTTP)
http://www.example.com:2251 -> Failure: different port
http://data.example.com/dir/other.html -> Failure: different hostname
https://www.example.com/home/index.html.html -> Failure: different protocol
ftp://www.example.com:21 -> Failure: different protocol & port
https://google.com/search?q=james+bond -> Failure: different hostname & protocol
Workaround

Monday, April 3, 2017

Get Google contacts with Javascript using Google Contacts API and OAUTH 2.0

To get the Google Contacts with Javascript using Google Contacts Api

To Pull the google contacts we need to create a project in google developer console

Create a Google application in Google Developers Console for obtaining your Client id and Client secret

  • Go to Google Google Developers Console and login with your google account.
  • create one a project by clicking Create Project Button
  • Go into the newly created project
  • Click On the Menu icon and select the Api Manager Link
  • Search for “Contacts API” and click on it
  • Enable the “Contacts API” by hitting the “Enable API” button
Below is the code to pull the contacts from google relplace client id with newly created client id