When you host Googles web search element on a page, a div is created which incorporates an iframe which points to a Google adsense ads page. However, if there are no ads for the specific query, Google somehow changes the class on YOUR domain to render the div (and iframe) invisible.
They are NOT using postMessage, as it also works in IE7. They are also not using the fragment identifier method, as no hash appears in the url. So how do they do it?
To check what I'm saying just put the following into a regular html page:
<!-- Google Custom Search Element -->
<div id="cse" style="width:100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1');
google.setOnLoadCallback(function(){
new google.search.CustomSearchControl().draw('cse');
}, true);
</script>
and then do a search for "cars" (or anything else that will definitely have ads) and then for "wzxv", which has no ads...
The script is included in your frame, so it can do to your page whatever it wants. Cross-domain restrictions only count for scripts in iframes referencing things in outer scripts from foreign domains. google.load('search', '1'); runs in your frame, owned by your domain, free of any restrictions.
The script fragment is executing in the DOM of your page, not in the ads IFrame. It creates the IFrame as a child element of the parent div in your HTML and sets its URL to load the ads, but since it's running as part of your page, it can also choose to hide the parent div instead.
Update: The script can easily run an Ajax query to the ad server and choose what to do based on the response. In fact, the script might be dumb enough to not even care about the response and just render it in the DOM and the ad server can just return another script that does the proper thing based on the result - hides the parent div or injects the ads iframe. Heck, the ad server can directly return the proper HTML to replace the whole parent div, if necessary. All the initial script needs to know and pass along with the Ajax query is the name of its parent div, which you pass to it as a parameter.
the answer is one word lenght: jsonp
Related
I have setup DFP to return a list of Custom Creatives. Each of these creavtives contains the following HTML:
<a href='%%CLICK_URL_UNESC%%' class='drop-down-ad'>Ad Link Text</a>
When these creatives are rendered to the page I have some JavaScript that finds all the anchor tags containing the class drop-down-ad and grabs the src attribute and stops the page from changing when clicked and loads content in via ajax. I do not want the page to change but I would like to still tell DFP that the user click the link. I am not sure if this functionality is supported by DFP?
Is making a request to the generated CLICK_URL_UNESC using ajax supported by DFP? Or is this not a thing I should be doing.
Hopefully I have explained what I am trying to do ok. Let me know if you have any questions.
I've been searching for a couple hours and haven't found a solution. Hopefully you can help.
I want to get the name & path of the parent page within an Iframe. The reason for this is to prevent the page within the Iframe to be displayed outside it's intended location. If I can get the session variables of the parent page, that would be even better as I could verify the user.
The Iframe will be written in ASP.NET, while the parent page is PHP.
I have found Javascript code that might work, but I'm very unfamiliar with javascript and how to pass the return value to the code behind in ASP.NET. If your solution involves javascript, I will need the whole thing from calling it in the form load to getting back the value.
I have tried these functions, but they don't show what I need.
Request.Url.AbsoluteUri.ToString
Request.ApplicationPath.ToString
Request.UrlReferrer.AbsolutePath.ToString
Thanks
I understand that you looking for a code behind solution and redirect, but the code behind can not recognize if the page is calling from some other.
You may try the Request.ServerVariables["HTTP_REFERER"] but this can make mistake, and can even been disable by some users, or changed.
One simple working solution with javascript is to check on the iframe it self if its inside your master page or not. So this code go to the page that lives inside the iframe, and if see that is alone is redirect the user back to the master page.
<script type="text/javascript" language="javascript">
// this line is check if its inside an iframe.
// if top==self then is not in iframe
if(top == self)
{
alert("This page can not be viewed alone, please press ok to load the master page");
top.location.replace("MasterPage.aspx");
}
</script>
My page loads an IFRAME with content from another domain (and I don't have control over the content) that contains links with target="_top" attribute. My page gets completely replaced once the user clicks on one of these links. Since my page is a stateful web application it would confuse the user.
Is there a way/trick to stop those IFRAME links to do so? They should either (visually) load within the IFRAME or open in a new window.
I don't want to proxy the IFRAME using a server script and alter the HTML code since this would block any user cookies for the foreign domain.
Perhaps some special trick like nested IFRAMEs or whatever could do this?
I have two scripts inside my webpage
<script type="text/javascript" src="http://somesite/somefile.js"></script>
<script type="text/javascript" >somecode('a','1z4j73');</script>
This script is generating a visitor map on my web page, now I don't want my user to click on the script and get redirect to that website.
How can I restrict that?
can I make a div tag and make all element inside the div tag to read only?
I have make sure that this restriction doesn't falls under company rules, they just want their logo under the map.
EDIT1
Can I catch this thorugh any event and again redirect the user to the default page?
Like when user click the image, I check the URL and if the URL contains that site name I again redirect to the default page.
I guess you create the sitemap for search engine optimization, and would like to keep sitemap links accessible for search engines (indexers), but want to get rid of redirect functionality for visiting users.
If that is so, then all you need to do - is just to assign your own onclick function to all links in your sitemap.
// onClick event
onClickFunction = function ( ) {
return function ( ) {
// do nothing
return false;
}
};
something
or simply:
something
this will still work for search indexers, which will look for all <a> tags and read href value. But because of "return false;" in the onClick event handler function - the redirection for users will be disabled.
Please see this article
http://www.bradino.com/javascript/onclick-return-false/
If you can figure out what the HTML elements are that you don't want, you can remove them using a script library like JQuery:
$("#targetelement").remove();
Or replace it with your own content.
You don't need a script library to do this though, but it can be helpful to have one.
HTH.
I have an asp.net site using the Google Mini. I have a search box on the masterpage that redirects to a search results page that displays the results in an iFrame. This approach is all taken from the documentation provided by Google for the Mini and seems pretty simple.
What the doc doesn't cover (or I can't find) is that clicking on any of the result that might be another .aspx page, opens that page with all of it's masterpage glory right inside the iFrame which is obviously not desired. I end up with a page in a page.
Short of grabbing the xml search results and manipulating that myself, how do I just get the search result links to open like a normal page?
You can add this javascript into your masterpage to make it break out of the iframe when the user clicks the link
<script type="text/javascript">
try
{
if (self.parent.frames.length != 0)
self.parent.location=document.location;
}
catch (Exception) {}
</script>
Another way of doing this would be to use the target attribute of the anchor (<a>) tag. If I remember correctly that would be
Link
I've used the javascript solution myself before and it works, I've not tested the target.