Script generated image onclick event change - asp.net

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.

Related

Detect Click On Iframe Then Do An Action

I want to add a iframe to my website that has a button in it and when someone clicks on it, it does an action like maybe forward to another page or echo a message. I don't care about the code whether its java, php, html, etc as long as it works. I'm good at coding certain things but this is not one of them, help me out please.
UPDATE:
the iframe is:
iframe src="http://ipget.tk" /iframe
when its clicked on I want it to go to google.com
the iframe will be on a test page on scazioco.com
Using Jquery you can bind an event to your IFrame :
$('#iframe_id').bind('click', function(event) {
window.location = http://www.google.com
});
Replace #iframe_id with the actual Iframe's ID

is it possible to not reload user control when redirect to a page?

I have created a user control for side menu navigation and when user clicks on one of the item on a menu, it displays details of the company and information. Now it is redirecting to different page for each company using passing parameter (ex. company.aspx?ID=10) and everytime when I clicked, it refreshes whole page. I would like to keep side menu user control without refresh as there is a live search option.
Is this possible? or should I change opposite way to do it? should be the side menu in a page and company info in a user control??
If you want to do a proper way using Ajax, you'll need to change the entire site structure. Here is a quick and dirty way of doing it using jQuery.
<script>
$(document).ready(function () {
$("#left-pane a").click(function (e) {
e.preventDefault();
loadUrl($(this).attr("href"));
});
});
function loadUrl(url) {
$("#right-pane").load(url);
}
</script>
I think what you're talking about is partial page update, where, rather than posting and reloading the entire page, you only reload part of it.
Here's a good article: Understanding Partial Page Updates with ASP.NET AJAX

Need parent name of Iframe

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>

Mystery: How does Google do cross-domain iframe communication?

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

How can I get the Google Mini search results, using the iFrame, to not open in the iFrame

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.

Resources