Get URL of link clicked inside frame/object - iframe

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.

Related

How to get updated iframe source

How can i get the updated iframe src value after my user navigates throught the site that is inside the iframe?
I'm asking this because the src value is always the same! It don't change even if you navigate inside the iframe.
Thanks
easiest way is to use javascript to dynamicly refresh the <iframe> by setting the src to a given interval refresh rate.
Have a look at the below example
dynamicly refresh iframe without refreshing current page

Backbone Project, How to navigate back when there is a iframe within the view?

How to navigate back when there is a iframe within the view?
After user clicks on a link to other pages from within the iframe, the browser history gets append on to it as well so that I cant use "window.history.back()" to go back, since "-1" will take user back within iframe and not the actual app itself.
What is a good way to solve this so that when back button pressed its the previous "route" and not the history of iframe history?
try doing something like this, from the Iframe:
window.top.history.back();
or
back to backbone app
This way you are accessing the Iframe's parent window history, not the Iframe itself. As long as you navigate to the Iframe from your SPA, this should work.

How to open a url in new tab when user click menu item?

Currently, when the menu item is clicked on the web page in the event handler the new url is assigned to Response.Redirect and so it is opening in the same window. I want to be able to open the new url in a new tab keeping the main webpage open. I tried giving target="_blank" to the menu item and it doenst help . Can you suggest a solution?
I assume need to do a POST so you can calculate the new URL based on some posted data?
If that's the case, you could set target="_new" on the form tag - targets work for POSTs as well as GETs.
Or you could return the new URL to the client and then do a window.open when the page reloads.
Just attach a client side handler instead of a server side one.
Formally - instead of the "OnClick" attach "onmenuitemclick" to a javascript expression which opens new window - "window.open( ... )".

How to close aspx page that is redirect from handler

I am in critical situation.
In my application I try to close opened window using javascript function.
function Close_Window() {
var myWin = window.open('', '_parent', '');
myWin.close();
}
this function is used in 3 aspx pages.
That page will open from mail means my application is used for sending Mail.
In that such as normal newsletter there will be three footer links like UnSubscribe,Forward A Friend,Change E-Mail address.
So on click of close button for above these three pages I had written that code.
The page will be opened from “ashx” file. And I try to close it using Javascript.
So close button is working when I direct click on the above three links.
But by right clicking on that I open it in new window or new tab close button is not working.
So please give me solution that how can I close aspx page using javascript or in code behind.
My purpose is page should be close any how by javascript or by code behind.
Note : I am opening that page using ashx handler.
If you want total control of opening and closing windows, keep the control and do not transfer the control to the browser. The behaviour of Html is well defined by W3C. The behaviour of new browser windows/tabs will vary between different browsers, and probably in the future.
Why do you open and close a page directly?
Probably you want to execute a GET request on the server to trigger some action. Take a look at the jQuery get method. So you can execute your request, without the need to open/close a new page.
If you want the user to make a choice, after clicking the link, I would work with a jQuery modal dialog. This pops up a dialog, but inside the current HTML page. Therefor you are in control of closing the dialog.
If you open a new window/tab the browser is in control, and the behaviour depends on the browser / user settings combination.

How to get the url of the page which is currently loading in the iframe

I have an requirement that, in my application on clicking an button I have to load one more application with the same template which I was using for my application.
So, on clicking the button in my application I have used one intermediate page in that using iframe I passed that URL of an external application. Its working fine.
But the problem is in the external application which is not in my control on clicking an button it is moving to next page. In that page I want to hide an button.
I did that also using div tag color as white and set the positions.
But the problem is in all the pages in the same position that is affecting. So I want to get the URL of the page which is loading in the iframe on the second or third click of an external application, so that I can using some conditions I can hide the control.
You can use Javascript. Give the iframe an ID
var iframe = document.getElementById(id);
The url is accessible via the "src" attribute:
iframe.src
more info

Resources