iframes and redirection - iframe

I have a webpage (say www.example.com/a.asp) .. I am having an iframe in this page which loads a page from a different website (www.example.net/b.asp)... This b.asp asks few questions to the user and the results are posted to c.asp in my website (www.example.com/c.asp). This page (www.example.com/c.asp) gets loaded in the iframe. Is there any way so that I can reload the entire webpage and redirect to another wbpage when I get the response from www.example.net. Sorry if this question is confusing, Any queries please let me know.

As mentioned above, you can use the "_top" in the target for the form, or you could use some JavaScript on the result page to check and see if its the "top" page. All things being equal, you're better off avoiding the JavaScript as it won't work if the client has scripting disabled.

If i understand correctly i think you might be able to set the target for the post to c.asp to be "_top". This should reload the entire page getting you out of the iframe. Your c.asp page would have to handle the redirection you require.
Alternatively, the redirection that the c.asp page needs to perform may be able to target the "_top" itself, in case you can't change the page which posts the data.

Mhm, not sure if I got you right. Do you really mean when you got the response from abc.com rather than your own web site?
The form tag in HTML seems to have a target-attribute for loading the response to a specified (e.g. _top) target after submitting data:
http://de.selfhtml.org/html/referenz/attribute.htm#form (German)
Not sure if I really answered your question. Did I?
Cheers
Matthias

If you have no control over the resource loaded into the frame, you can't redirect using HTTP, so you are stick with JavaScript.
Given the same origin policy, I think the best you can do is to determine when a new document is loaded into the iframe.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<title>test of iframe</title>
<iframe width="500" height="400" src="http://example.net/">
<p>See The Example Site</p>
</iframe>
<script type="text/javascript">
window.onload = function () {
document.getElementsByTagName('iframe')[0].onload = function () {
window.alert('Document loaded in frame');
}
}
</script>
You can then set window.location (possibly after counting the number of times the event fires)

Related

Avoid reloading head scripts when page load via Ajax

I have a main page via a div. Many page are load into div via "load" function in jQuery.
When page loaded all script in head of page is load.
Is there a way to prevent scripts from being reloaded when the script is already loaded?
(Disclaimer: this architecture is wrong and should not be used. My response is only to address the OP's specific problem)
Try wrapping the head area of your pages in an if statement, which checks whether the request is ajax or not:
<%if(!Request.IsAjaxRequest){%>
<head>
...
</head>
<%}%>
Update
In response to OP's comment - Add a querystring parameter to every ajax request that happens after the first one. Use some JavaScript for that. Then change the if statement to check for that parameter:
<%if(String.IsNullOrEmpty(Request.QueryString["secondTime"]){%>
<head>
...
</head>
<%}%>

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>

ActiveX control works in HTML, but not (quite) in ASPX. What's the difference?

I’m trying to use a third-party ActiveX control on our intranet ASP.NET site, and I’ve run into a problem I can’t figure out.
Expected behavior: The control expects to see a specific variable in the URL (“msg”). If you provide it, it works. If you don’t provide it, it complains that the value is missing.
If I put the control in an HTML page, it works fine. But if I then change the page’s type to aspx, the control acts as if the variable isn’t there. The control still loads and runs; I’m not getting any permission or safety messages. But it complains that “msg” wasn’t provided on the URL.
In other words, if I try these URLs, the first one works fine; the second one gives me the "you didn't provide the msg parameter" complaint:
(works fine)
http://mysite.mydomain.com/controltest/test.html?msg=123
(complains)
http://mysite.mydomain.com/controltest/test.aspx?msg=123
I know the aspx version is being processed by the server before being sent to the client, but there aren’t any server-side commands or tags (it’s the same file, just copied and renamed). As far as I can tell, the resulting page that is sent to the client is exactly the same.
Is there something about aspx vs html that would cause the control to not be able to get that variable? I can see it fine from javascript that I add myself.
Here's the content of the page. Not much to it. If I get this working I intend to add some aspx tags and code, but there's no point yet.
<html>
<head>
<title>
ActiveX Control Test
</title>
</head>
<body>
<OBJECT ID="control1" CLASSID="..." CODEBASE="..." >
</body>
</html>
Turns out Eugene was correct, the third party control was doing a string search on the URL and was only looking for .html or .htm.

jQuery undefined in content page when using master pages which has jQuery reference

I have a nested master page. A parent master page, a child master page and a content page whose master page is the child master page. I have a reference to jQuery in the parent master page in the head section.<script type="text/javascript" src='<%#ResolveUrl("~/includes/jquery-1.4.2.min.js") %>' ></script> & Page.Header.DataBind(); in the OnLoad event.
I am using jQuery in all the pages including the master pages. However I am getting "Error: $().ready is not a function" in the content page. If I include jQuery reference in the content page it works.
Question: If the reference to jQuery is in the master page head section, why aren't the content pages able to use jQuery? When I do view source, the script tag with jQuery is there and it works.
The master pages and content page are merged during rendering and sent to the browser as a single html page so I am not sure when master pages are used, jQuery references break.
UPDATE:
When I changed '$.ready(function()' to 'jQuery(document).ready(function($)' it worked! I am not loading any other javascript libraries and I am not using MS Ajax.
First, and I didn't notice this before, but is your original call to $.ready(function() {}), which didn't work, but jQuery(document).ready(function() {}) did work? Does your call work if you use $(document).ready(function () {} )? Just wanted to make sure it's not a typo. The jQuery docs say the $.ready(function() {}) is valid, but it's not recommended.
OK, assuming it's not a typo, it definitely sounds like you have a conflict with the '$' variable. If you're using third-party controls or ASP.NET AJAX, you may run into conflicts (even though you may not be including the JS file explicitly).
If you could post what gets output by the browser after your page loads, that would help.
Also, if you run Fiddler (or some other traffic request tool), you can see if any JS references are being downloaded. Look not only for .JS files, but also .AXD files (some third-party tools name these files ScriptResource.axd or WebResource.axd, and they may redefine the '$' variable).
You may want to check out this link on the jQuery API page about the noConflict function. This helps when you have a conflict with the $ variable.
Without seeing the output, it's tough to diagnose. But hopefully this helps.
i also have the same issue, it sounds like a jQuery conflict
i fixed my issue :
<script type="text/javascript" >
$(document).ready(function () {
$.noConflict();
});
</script>
in the <head> section

Why Are There Multiple GET Requests Shown in Firebug?

So I'm at the stage in web programming where I'm past the "Look, Ma, I can put data in a grid and it shows up on the page." I'm now at the, wow, this site is not as snappy as I want it to be. So, I enabled the "Net" tab in Firebug, closed my eyes, crossed my fingers, and went spelunking.
The first thing I noticed is that all of my .aspx pages are being "GET"ed at least three times. Is this normal? If not, what is "normal"? What affects the "GET"ing of the .aspx pages? I'm assuming that includes the time it takes to hit the database and render all the controls on the page. Is that true?
Perhaps what would really benefit me is a place I can look to get some "best practices" for these kinds of speed related issues.
Things to consider:
Using IIS 6.0 via HTTPS
We're using Masterpages
We're using Telerik controls
A RadMenu
A RadScriptManager
I'm certainly more of a thick client guy than a web guy
EDIT
Answers to questions below:
The response code is 200
EDIT
Screen shot added:
FirebugScreenshot http://img187.imageshack.us/img187/5873/firebughelp.jpg
EDIT Added Additional Screenshot to include Request Headers
EDIT
Added links
page source
My Master file as txt
My WebConfig (without connection strings, obviously)
EDIT: Here is the source of your two extra page loads:
<script type="text/javascript"
src='<%# ResolveUrl("~/Common/jQuery/jquery-1.3.2.min.js") %>'>
</script>
<script type="text/javascript"
src='<%# ResolveUrl("~/Common/jQuery/jquery-ui-1.7.1.custom.min.js") %>'>
</script>
As you can see in the rendered version the src attribute is empty, causing it to load the page two extra times.
<script type="text/javascript" src=''></script>
<script type="text/javascript" src=''></script>
You can probably fix this by using the runat server tag and having it resolve the urls automatically.
<script type="text/javascript"
src="~/Common/jQuery/jquery-1.3.2.min.js"
runat="server"
ID="jQuery"> </script>
<script type="text/javascript"
src="~/Common/jQuery/jquery-ui-1.7.1.custom.min.js"
runat="server"
ID="jQueryUI"> </script>
(or change <%# %> to <%= %> -- since you need to have the version that outputs a string instead of the binding syntax).
Original answer removed since it was not related to the actual problem.
It's unlikely that those are AJAX requests, as the response length is the same on each request.
I'm also ruling out the bug with empty src attribute of img elements, as this only causes one reload of the page, not two.
There is a know bug with Telerik RadEditor that might cause such condition, but you don't mention it in the list of used controls. Here are more details about it:
http://www.telerik.com/community/forums/aspnet-ajax/editor/radeditor-forces-page-load-twice.aspx
You might also want to comment out the Telerik controls on the page to see if that helps.
The browser should normally hit the server just once, and all the time it takes to query the database and whatnot should be confined within that request. If you're playing around with ajax controls, they're likely to query the server more times for new data. You can use firebug to inspect the requests and responses, and see what they contain.
A common cause for the aspx being requested several times is having IMG tags rendered without any SRC attribute. This will default to querying the same page for the image source. If this is the case for you, then you could check the request headers in firebug, to see if it expects an image.
You could also go to the console and type document.images to get a list of all the images. The ones that aren't visible on the page will be shown slightly faded. Inspect those for blank SRC's.
This normally happen if you are in the Development Environment and "Enable browser link" in VS 2015/2013 .
To avoid the Multiple GET Requests Shown in Firebug, uncheck "Enable browser link" from the tool bar.
If you view the page source, you find script tag added to the page when you check "Enable Browser Link". This causes Get/Post Actions to the iis server. For more details: http://www.asp.net/visual-studio/overview/2013/using-browser-link
The browser makes a GET request for each resource included in the Page, including js files, images, css files...
It could be lots of things - the important part of the request is what it's GETing.
Generally you're going to see more than one request for an ASPX page as it loads the javascript libraries to perform validation and postbacks. Controls can also have javascript embedded as resources, which in turn create other GET requests, usually for WebResource.axd and ScriptResource.axd.
If you have security enabled, that could be the challenge and response requests - first a 401 then a 200. What are the response codes that you are getting?

Resources