Window Support Software

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, 4 December 2012

Hide Content Based Upon Iframe Parent

Posted on 12:06 by Unknown
Some web sites use iframes to display information from other web servers.  This is a practice that is generally frowned upon yet is a necessary evil sometimes.

I work on an employee intranet where we need to display content from another internal server.  The problem is that sometimes our employees access the site from off of our domain where they don't have access to the internal server.  To get around this issue I've created an extremely simple javascript snippet which can be added to the page to hide the content and display a message to the user explaining why they can't see the content.

I'm posting it here as a reference for myself and in case someone out there needs something like this!


<div id="whatever">Your content</div>

<STYLE type=text/css>
   .hidden { display: none; }
</STYLE>

<script type="text/javascript">

   function referrerCheck()
   {
      var mapReferrer = document.referrer;
      var mapDiv = document.getElementById('content');

      if(mapReferrer=="http://this is the URL calling the iframe")
      {
         mapDiv.className='unhidden';
      }else{
         mapDiv.className='hidden';
      }
   }

   referrerCheck();

</script>

How it works:
  1. All of this code goes onto the page which calls the iframe.
  2. The div at the top is where your iframe goes - what you want to hide if folks are off the domain.
  3. The style section sets the stage for what you want to happen if folks are off the domain.  In this case we want to not display the entire div.
  4. The javascript runs the referrerCheck() function which grabs the document.referrer which is the page that calls the iframe.
  5. The getElementById functions gets the div object so that its class can be manipulated.
  6. The If condition then determines whether or not the referrer is on or off domain and sets the class accordingly.
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

Categories

  • 64bit
  • access a help link
  • Active Directory
  • AD
  • Adaptive Layouts
  • Administrator account
  • Antimalware programs
  • binary
  • collaboration
  • content management
  • content migration
  • CSS
  • Data Connection
  • Data execution prevention
  • Ease your work
  • Eclipse
  • Email accounts
  • Email in Outlook
  • End process
  • Excel
  • hosting
  • iCalendar
  • ics
  • IIS
  • install
  • Interact-Intranet
  • Intranet
  • Jive Express
  • Jive SBS
  • Jive Software
  • Knowledge Directory
  • Liferay
  • Liferay Developer Studio
  • Linux
  • Local Computer Policy
  • login
  • Microsoft chat
  • Microsoft Help
  • Microsoft support
  • Microsoft tech support
  • Microsoft word application
  • Minimum hardware requirements
  • Mozilla Firefox web browser
  • MS SQL 2008
  • New Mail Notification
  • Oracle
  • Oracle ECM
  • Oracle Enterprise Content Management
  • Oracle OpenWorld
  • Oracle WebCenter
  • Oracle WebCenter Analytics
  • Oracle WebCenter Analytics 10.3.0.1
  • Oracle WebCenter Interaction
  • Oracle WebCenter Suite
  • Outlook 2007
  • Outlook Express Address Book
  • Outlook Repair
  • Outlook repair utility
  • Outlook settings
  • Outlook support
  • Outlook tech support
  • Password protection
  • Plumtree
  • portals
  • Programs and Features
  • Publisher
  • RCU
  • redirect
  • Remove AVG toolbar
  • Remove malwares
  • Screen Scraping
  • Search
  • set password
  • SharePoint
  • SQL
  • SQL Server Reporting Services
  • Studio
  • Task manager
  • try Windows 8
  • Underline feature
  • vanity URL
  • Vista problems
  • WCI
  • WebCenter Interaction
  • WebCenter Suite
  • WebLogic Server
  • Windows 7 Support
  • Windows 8 Support
  • Windows 8 transfer
  • Windows Blue
  • Windows Easy Transfer tool
  • Windows live chat support
  • Windows Live Photo Gallery
  • Windows Online Support
  • Windows Server 2008
  • Windows support
  • Windows Vista help
  • Windows XP support
  • WLS
  • Xbox 360 controller

Blog Archive

  • ►  2013 (33)
    • ►  December (1)
    • ►  November (1)
    • ►  October (8)
    • ►  August (2)
    • ►  July (4)
    • ►  June (4)
    • ►  May (3)
    • ►  April (2)
    • ►  March (2)
    • ►  February (1)
    • ►  January (5)
  • ▼  2012 (32)
    • ▼  December (4)
      • Install The GIF Support On To Your Windows Machine
      • Interact Intranet: Automate the Extraction of Bina...
      • How to Set Password on Your Windows XP
      • Hide Content Based Upon Iframe Parent
    • ►  November (5)
    • ►  October (2)
    • ►  September (7)
    • ►  August (1)
    • ►  July (1)
    • ►  June (8)
    • ►  May (2)
    • ►  April (1)
    • ►  March (1)
  • ►  2011 (30)
    • ►  November (3)
    • ►  October (2)
    • ►  September (2)
    • ►  August (4)
    • ►  July (3)
    • ►  June (5)
    • ►  May (4)
    • ►  April (2)
    • ►  March (3)
    • ►  January (2)
  • ►  2010 (8)
    • ►  December (2)
    • ►  November (1)
    • ►  October (5)
Powered by Blogger.

About Me

Unknown
View my complete profile