Detect Click On Iframe Then Do An Action - iframe

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

Related

Using browser back button to navigate between the website pages

I have search this but didn't get useful information. In my website I have a order processing scenario. currently I am using a "back" button on page to go to the previous order page. I want to go back through the browser back button. I want the code which I added in page back button can run when I use the browser back button.
How I achieve this..?
try like this
$(document).ready(function(){
$('a.back').click(function(){
parent.history.back();
return false;
});
});
here the link is the one on which click you want to go back
or even better
have a look at this
History.go can do that:
parent.history.go(-1);

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>

Script generated image onclick event change

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.

Get URL of link clicked inside frame/object

So, I have a page (page1.html) and then I have an iframe or object serving up some other page (page2.html) within that page... What I want/need is when the user clicks a link inside the iframe (page2.html) i need a way for page1.html to recognize that the iframe href has changed because the link is loaded into the iframe.
There is no onload event for the object/iframe element so i can't figure out when the user has clicked a link inside the IFRAME (page2.html)...
You have very little control over what happens in an iFrame. Essentially, once you load it, you have no power over it, and you can't see what happens in it. (You can still tell it to load something else.) If you want that sort of control, you should really be using AJAX, i.e. you should be loading new content into the document object model dynamically.
right click on the link and then click open in a new tab / new window, this will open the webpage in a new tab , then copy the url from the address bar of the browser.

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