Tuesday, 4 February 2014

Safari: Setting third party iframe cookies

Safari is known to be strict about permissions in iframes, especially when the domain of the iframe page is different from the domain of the parent page. Some would even say paranoically strict.

Safari will block you from setting cookies for the third-party domain (the different domain in the iframe), unless you already have cookies set for that domain.

Here's a snippet of javascript I pulled together last week that as a way to get around the iframe cookie security. It works great if your page is nice and light and loads fast, otherwise it can feel pretty clunky with the triple loading...

window.onload=function(){
 if(navigator.userAgent.indexOf('Safari')!=-1&&navigator.userAgent.indexOf('Chrome')==-1){
  var cookies=document.cookie;
  if(top.location!=document.location){
   if(!cookies){
    href=document.location.href;
    href=(href.indexOf('?')==-1)?href+'?':href+'&';
    top.location.href =href+'reref='+encodeURIComponent(document.referrer);
   }
  } else {
   ts=new Date().getTime();document.cookie='ts='+ts;
   rerefidx=document.location.href.indexOf('reref=');
   if(rerefidx!=-1){
    href=decodeURIComponent(document.location.href.substr(rerefidx+6));
    window.location.replace(href);
   }
  }
 }
}

Here's what it basically does:
  • The javascript is placed in the page loaded inside the iframe. 
  • If the JS is run inside the iframe and the browser is Safari and there are no cookies set, then we frame-burst the page to take over the window and append the original parent page URL as a parameter. 
  • If the JS is run not inside a frame and the browser is Safari, then we set a timestamp cookie (now that we are out of the iframe) and if a reref param exists we redirect back to the original page.
  • If the JS is run inside the iframe and the browser is Safari and there ARE cookies set, then we do nothing.

And one more time in pseudo-code

if(browser is Safari){
 if(we are in an iframe){
  if(no cookies){
   set window_url = iframe_url + reref=iframe_parent_url;
  }
 } else {
  set a timestamp cookie;
  if(reref exists in url){
   redirect to original url so we have iframe again
  }
 }
}

530 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I am testing out your code. I am assuming that the part that I have to edit is the one with the interrogation marks inside single quotes?

    Do you know if this works with IE9+? Because I have this issue with IE9.

    ReplyDelete
    Replies
    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Online Training from India . or learn thru JavaScript Online Training from India. Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

      Delete
  3. I can't get this to work.

    If I have domainA.com with iframe loading domainB.com. The javascript above should be in domainB.com, right?

    This is what I have: http://pastie.org/9280470

    ReplyDelete
  4. Thank you. This made a world of difference! :) It worked beautifully!

    ReplyDelete
  5. I am facing issue with triple loading ?Please help me out to avoid that

    ReplyDelete
  6. Thanks.. it works!!

    ReplyDelete
  7. Thank you, it was very helpful!

    ReplyDelete
  8. This was a lifesaver. Thanks!

    ReplyDelete
  9. Since this was geared towards normal GET requests, is there a way that this could be easily modified to handle POST requests?

    I have a web app where the top frame POSTs into the iframe. So the initial call into the iframe is a POST request. Might be hard to carry those POST variables throughout the various redirects.

    ReplyDelete
  10. Hello the JavaScript must be placed into the page where the iframe is referring to ?

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Hello and omg, it to hard to understand those complicated settings such as for me. Better to download latest https://yepdownload.com/safari safari windows 8.1 from the begining, than try to understand those codes. I like this browser, from that moment when I start use the iphone, before I applied the chrome every day, but now only safari browser. For me here is convenient the read mode and the confidential system is very high.

    ReplyDelete

  15. Ingin Menjadi Jutawan Dalam Bermain Game Online, Inilah saat'a Anda Bergabung Bersama s128 sabung ayam, Pendaftaran Gratis Dan Akan Di berikan Panduan Cara Memenangkan Game Online. Bolavita Juga Menyediakan Promo Bonus Setiap Deposit 10% Utk New Member, Adalagi gan yaitu Bonus CashBack 10% Setiap Minggu'a, Jangan Lupa Di Like Juga FB Bolavita guys, Cara'a Sangat Gampang gan BBM: D1A1E6DF/ Wa: 081377055002/ Line: cs_bolavita Atau Kunjungi FB Bolavita Lalu Like Dan Share ya gan. thx ya gan ^_^

    ReplyDelete
  16. Hi Thanks for the nice information its very useful to read your blog.
    Web Design Training

    ReplyDelete
  17. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    fire and safety course in chennai

    ReplyDelete
  18. This is very good content you share on this blog. it's very informative and provide me future related information.
    Java training in Chennai

    Java training in Bangalore

    ReplyDelete
  19. I appreciate that you produced this wonderful article to help us get more knowledge about this topic.
    I know, it is not an easy task to write such a big article in one day, I've tried that and I've failed. But, here you are, trying the big task and finishing it off and getting good comments and ratings. That is one hell of a job done!


    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  20. .................................................................................
    read online info.

    ReplyDelete
  21. I Regreat For Sharing The information The InFormation shared Is Very Valuable Please Keep Updating Us Time Just Went On Reading The Article Python Online Training AWS Online Training Hadoop Online Training Data Science Online Training

    ReplyDelete
  22. Such an ideal piece of blog. It’s quite interesting to read content like this. I appreciate your blog
    Data Science Certification

    ReplyDelete
  23. simply superb, mind-blowing, I will share your blog to my friends also
    I like your blog, I read this blog please update more content on hacking,Nice post
    Tableau online Training

    Android Training

    Data Science Course

    Dot net Course

    iOS development course

    ReplyDelete
  24. Thanks for sharing valuable article having good information and also gain worthful knowledge.

    Oracle Integration cloud service online training

    ReplyDelete
  25. Thank you for sharing your awesome and valuable article this is the best blog for the students they can also learn.

    Workday HCM Online Training

    ReplyDelete
  26. PPSSPP iOS is a free emulator allowing you to play PSP games on your iOS device at high definition and extra features. The software is compatible with iOS 6, 7, 8, 9, 10, 11 and iOS 12. It runs almost all popular games but depending on your device power, not all will run at full speed.

    ReplyDelete
  27. An amazing web journal I visit this blog, it's unbelievably wonderful. Oddly, in this blog's content made without a doubt and reasonable. The substance of data is informative.
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  28. A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  29. A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  30. Just now I read your blog, it is very helpful nd looking very nice and useful information.
    Digital Marketing Online Training
    Servicenow Online Training
    EDI Online Training

    ReplyDelete
  31. Great blog created by you. I read your blog, its best and useful information.
    AWS Online Training
    Devops Online Training
    Apllication Packaging Online Training

    ReplyDelete
  32. Thanks for this post, I really appriciate. I have read posts,
    all are in working condition. and I really like your writing style.
    autocad in bhopal
    3ds max classes in bhopal
    CPCT Coaching in Bhopal
    java coaching in bhopal
    Autocad classes in bhopal
    Catia coaching in bhopal

    ReplyDelete
  33. The article is so informative. This is more helpful for our
    software testing training institute in chennai
    selenium training Thanks for sharing

    ReplyDelete
  34. Permainan Bandar Q atau yang lebih di kenal dengan Bandar Judi Keliling saat ini memang sedang naik daun di dalam kancah perjudian online di seluruh Indonesia
    asikqq
    dewaqq
    sumoqq
    interqq
    pionpoker
    bandar ceme
    hobiqq
    paito warna
    forum prediksi

    ReplyDelete
  35. I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.is article.

    ReactJS Online Training

    ReplyDelete
  36. An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  37. thanks for your information really good your work web design company in velacheryQbigpro branding solution is the best web design company in velachery web design company in velachery.we will create the web site and managing the site.we will help for all business.website is very important for all business.

    ReplyDelete
  38. An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  39. thanks for your information really good and very nice web design company in velacheryQbigpro branding solution is the best web design company in velachery web design company in velachery.we will create the web site and managing the site.we will help for all business.website is very important for all business.

    ReplyDelete
  40. For the best Python training in bangalore, Visit:
    Python training in bangalore

    ReplyDelete
  41. nice blog
    get best placement at VSIPL

    get digital marketing services
    seo network point

    ReplyDelete
  42. nice blog
    get best placement at VSIPL

    get digital marketing and web development service
    seo network point

    ReplyDelete
  43. nice blog
    get best placement at VSIPL

    get digital marketing and web development service
    seo network point

    ReplyDelete
  44. awesome blog it's very nice and useful i got many more information it's really nice i like your blog styleweb design company in velachery

    ReplyDelete

  45. This article is really great and helpful. I would request you to please provide some more links and material where we can have more information about your blog. Thanks for sharing a post
    Python training in bangalore

    ReplyDelete
  46. For Data Science training in Bangalore, Visit:
    Data Science training in Bangalore

    ReplyDelete
  47. Nice Post
    For AWS training in Bangalore, Visit:
    AWS training in Bangalore

    ReplyDelete
  48. For Devops Training in Bangalore visit:
    Devops Training in Bangalore

    ReplyDelete
  49. Thank you so much for sharing this amazing article with us. Will stay connected with your blogs for the future posts.
    Python training in bangalore
    Python training in Bangalore
    Data science with python training in Bangalore

    ReplyDelete
  50. Thanks for sharing the valuable information here. So i think i got some useful information with this content. Thank you and please keep update like this informative details.


    wedding catering services in chennai
    birthday catering services in chennai
    corporate catering services in chennai
    taste catering services in chennai
    veg Catering services in chennai

    ReplyDelete
  51. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    microservices online training

    ReplyDelete
  52. Hello Admin!

    Thanks for the post. It was very interesting and meaningful. I really appreciate it! Keep updating stuffs like this. If you are looking for the Advertising Agency in Chennai / Printing in Chennai , Visit us now..

    ReplyDelete
  53. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    microservices online training
    best microservices online training
    top microservices online training

    ReplyDelete
  54. Good Information Thanks for Sharing
    Soft Online Provides best training for Oracle Fusion and EBS Courses with 100% Placements
    Oracle EBS Training in Hyderabad
    Oracle Fusion SCM Training
    Oracle Fusion HCM Training
    Oracle Fusion Financials Training
    For more info Visit us: www.softonlinetraining.com

    ReplyDelete
  55. It is really explainable very well and i got more information from your site.Very much useful for me to understand many concepts and helped me a lot.microsoft azure training in bangalore

    ReplyDelete
  56. Congratulations This is the great things. Thanks to giving the time to share such a nice information.python training in bangalore

    ReplyDelete
  57. The Information which you provided is very much useful for Agile Training Learners. Thank You for Sharing Valuable Information.google cloud platform training in bangalore

    ReplyDelete
  58. Excellent post for the people who really need information for this technology.selenium training in bangalore

    ReplyDelete
  59. Very useful and information content has been shared out here, Thanks for sharing it.blue prism training in bangalore

    ReplyDelete
  60. Awesome post with lots of data and I have bookmarked this page for my reference. Share more ideas frequently.oracle apps scm training in bangalore

    ReplyDelete
  61. I must appreciate you for providing such a valuable content for us. This is one amazing piece of article.Helped a lot in increasing my knowledge.vmware training in bangalore

    ReplyDelete
  62. Awesome post with lots of data and I have bookmarked this page for my reference. Share more ideas frequently.data science training in bangalore

    ReplyDelete
  63. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article. devops online training

    ReplyDelete
  64. A IEEE project is an interrelated arrangement of exercises, having a positive beginning and end point and bringing about an interesting result in Engineering Colleges for a particular asset assignment working under a triple limitation - time, cost and execution. Final Year Project Domains for CSE In Engineering Colleges, final year IEEE Project Management requires the utilization of abilities and information to arrange, plan, plan, direct, control, screen, and assess a final year project for cse. The utilization of Project Management to accomplish authoritative objectives has expanded quickly and many engineering colleges have reacted with final year IEEE projects Project Centers in Chennai for CSE to help students in learning these remarkable abilities.



    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai


    ReplyDelete
  65. thanks for such an useful and informative stuff..

    learn aws

    ReplyDelete
  66. A IEEE project is an interrelated arrangement of exercises, having a positive beginning and end point and bringing about an interesting result in Engineering Colleges for a particular asset assignment working under a triple limitation - time, cost and execution. Final Year Project Domains for CSE In Engineering Colleges, final year IEEE Project Management requires the utilization of abilities and information to arrange, plan, plan, direct, control, screen, and assess a final year project for cse. The utilization of Project Management to accomplish authoritative objectives has expanded quickly and many engineering colleges have reacted with final year IEEE projects Project Centers in Chennai for CSE to help students in learning these remarkable abilities.



    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai


    ReplyDelete
  67. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    workday studio online training

    ReplyDelete
  68. thank you so much for this nice information Article, Digitahanks for sharing your post with us.dot net training in bangalore

    ReplyDelete
  69. I am a regular reader of your blog and I find it really informative. Hope more Articles From You.Best Tableau tutorial videos with Real time scenarios . hope more articles from you.

    ReplyDelete
  70. Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up...

    Start your journey with Database Developer Training in Bangalore and get hands-on Experience with 100% Placement assistance from experts Trainers @Bangalore Training Academy Located in BTM Layout Bangalore.

    ReplyDelete
  71. I read this post your post so nice and very informative post thanks for sharing this post.

    Real Time Experts provides Best SAP PM Training in Bangalore with expert real-time trainers who are working Professionals with min 8+ years of experience in Java Training Industry, we also provide 100% Placement Assistance with Live Projects on Java Training.

    ReplyDelete
  72. Post is very useful. Thank you, this useful information.

    Start your journey with AWS Course and get hands-on Experience with 100% Placement assistance from Expert Trainers with 8+ Years of experience @eTechno Soft Solutions Located in BTM Layout Bangalore.

    ReplyDelete
  73. This post is really nice and informative. The explanation given is really comprehensive and informative . Thanks for sharing such a great information..Its really nice and informative . Hope more artcles from you. I want to share about the best java video tutorials with free bundle videos provided and java training .

    ReplyDelete
  74. We as a team of real-time industrial experience with a lot of knowledge in developing applications in python programming (7+ years) will ensure that we will deliver our best in python training in vijayawada. , and we believe that no one matches us in this context.

    ReplyDelete
  75. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts.Real Time Experts training center bangalore

    ReplyDelete
  76. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.Prathima Infotech training center bangalore


    ReplyDelete
  77. We as a team of real-time industrial experience with a lot of knowledge in developing applications in python programming (7+ years) will ensure that we will deliver our best in python training in vijayawada. , and we believe that no one matches us in this context.

    ReplyDelete
  78. This comment has been removed by the author.

    ReplyDelete
  79. Snapdeal Winner List here came up with an Offer where you can win Snapdeal prize list 2020 by just playing a game & win prizes.
    Snapdeal winner name2020 also check the Snapdeal lucky draw2020

    ReplyDelete




  80. I am really happy to say it’s an interesting post to read . I learn new information from your article , you are doing a great job . Keep it up and a i also want to share some information regarding selenium online training and selenium training videos


    ReplyDelete
  81. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    workday studio online training
    best workday studio online training
    top workday studio online training

    ReplyDelete
  82. BMIT – BSc Medical Imaging Technology – Here is the details about Best BSc Medical Imaging Technology Colleges In Bangalore. If you are looking to study in Bangalore, the below link will redirect to a page that will show the best BMIT colleges in Bangalore
    BSc Medical Imaging Technology Colleges In Bangalore

    ReplyDelete
  83. BSc Cardiac Care Technology – Here is the details about Best BSc Cardiac Care Technology Colleges In Bangalore. If you are looking to study in Bangalore, the below link will redirect to a page that will show the best BCC colleges in Bangalore
    BSc Cardiac Care Technology Colleges In Bangalore

    ReplyDelete
  84. BBA Aviation – One of the most demanding management course in recent times. Here is the details of Best BBA Aviation colleges in Bangalore. If you are looking too study in Bangalore, visit the below link.
    BBA Aviation Colleges In Bangalore

    ReplyDelete
  85. GrueBleen – One of the best branding and marketing agency in Riyadh- Saudi Arabia. If you need the details, click the below link
    Branding Agency Riyadh
    Marketing Agency Riyadh

    ReplyDelete
  86. Agriculture Solutions – Taldeen is a plastic manufacturing company in Saudi Arabia. They are manufacturing agricultural plastic products like greenhouse cover and hay cover. Visit the below link to know more details
    Agriculture Solutions
    Greenhouse Cover

    ReplyDelete
  87. BSc Perfusion Technology – If you are looking to study BSc Perfusion Technology in Bangalore, just check out the following link. In that link you can get the details of Best BSc Medical Imaging Technology colleges in Bangalore
    BSc Perfusion Technology Colleges in Bangalore

    ReplyDelete
  88. GrueBleen – One of the best social media marketing agency in Riyadh- Saudi Arabia. Visit here for the all service details of GrueBleen.
    Social Media Marketing Agency

    ReplyDelete
  89. This comment has been removed by the author.

    ReplyDelete
  90. After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.
    data analytics cours mumbai

    data science interview questions

    business analytics course

    ReplyDelete
  91. I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.
    data science course Mumbai
    data analytics courses Mumbai
    data science interview questions

    ReplyDelete
  92. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article. best devops online training

    ReplyDelete
  93. Digital marketing makes possible to businesses to come out from traditional practices of marketing and try new and innovative techniques to grow faster.
    ExcelR Digital Marketing Courses In Bangalore

    ReplyDelete
  94. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    servicenow online training

    ReplyDelete
  95. An outstanding share! I've just forwarded this onto a co-worker who has been doing a little homework on this. And he in fact bought me lunch due to the fact that I found it for him... lol. So allow me to reword this.... Thanks for the meal!! But yeah, thanks for spending time to discuss this issue here on your web site.

    Cloud tech

    ReplyDelete
  96. Great efforts put to publish these kinds of articles that are very useful to know. I’m thoroughly enjoying your blog. And Good comments create great relations. You’re doing an excellent job. Keep it up.

    Magento Development Training Course in Chennai Zuan Education

    Selenium Training Course in Chennai Zuan Education

    ReplyDelete
  97. We as a team of real-time industrial experience with a lot of knowledge in developing applications in python programming (7+ years) will ensure that we will deliver our best inpython training in vijayawada. , and we believe that no one matches us in this context.

    ReplyDelete
  98. Having read this I believed it was extremely informative. I appreciate you taking the time and effort to put this information together.Snapdeal winner 2020 | Dear customer, you can complain here If you get to call and SMS regarding Snapdeal lucky draw, Mahindra xuv 500, lucky draw contest, contact us at to know the actual Snapdeal prize winners 2020.
    Snapdeal winner 2020
    Snapdeal lucky draw winner 2020
    Snapdeal lucky draw contest 2020
    snapdeal winner prizes 2020

    ReplyDelete
  99. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. data analytics courses

    ReplyDelete
  100. This is a wonderful article, Given so much info in it, Thanks for sharing. CodeGnan offers courses in new technologies and makes sure students understand the flow of work from each and every perspective in a Real-Time environmen python training in vijayawada. , data scince training in vijayawada . , java training in vijayawada. ,

    ReplyDelete
  101. This post is really nice and informative. The explanation given is really comprehensive and useful.

    learn hadoop

    ReplyDelete
  102. Really awesome blog!!! I finally found great post here.I really enjoyed reading this article. It's really a nice experience to read your post. Thanks for sharing your innovative ideas. Excellent work! I will get back here.
    Data Science Course
    Data Science Course in Marathahalli
    Data Science Course Training in Bangalore

    ReplyDelete
  103. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. satta king

    ReplyDelete
  104. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. Satta king

    ReplyDelete
  105. It’s hard to come by experienced people for this subject, works but you seem like you know what you’re talking about! Thanks

    ReplyDelete
  106. This is a wonderful article, Given so much info in ExcelR Digital Marketing Course Pune it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.

    ReplyDelete
  107. With the help of creative designing team TSS advertising company provides different branding and marketing strategies in advertising industry...

    https://www.tss-adv.com/branding-and-marketing

    ReplyDelete
  108. Hello there! I sincerely need to provide you a massive thumbs up on your exceptional facts you have got right right here in this publish. net I'll be coming back to your net site for extra quickly.

    ReplyDelete