Load aspx in div or adjust the size of an iframe - asp.net

I have an htm file with an iframe and a menu structure. The menu can load an htm file in the iframe or an aspx file. No problem at all.
But... Now they want the iframe to get the size of its content. (So there will be no scrollbar in the iframe, but you have to scroll the whole htm file.)
I didn't get this to work so I thought I would use a div for this issue. But I can't get the aspx file to load in a div.
So I'm stuck. Either I have to find a way to let my iframe grow or I have to find a way to load an aspx file in a div.

Placing the remote content directly in a div will be the easiest here, otherwise you will have to try and automatically size the iframe after the page loads, and it might even change height after that too.
To load HTML content from a remote source into a div you will need to look at the XML HTTP Objects exposed to the browser via javascript.
It sounds like you are not familiar with the concept so I would advise using a Javascript library like jQuery to help you along.

Related

Prevent Google Chrome Content Scripts from interfering with webpage DOM CSS definitions

I am building a Chrome extensions which injects a decent amount of JavaScript, CSS, and HTML into the page DOM for the current webpage tab. It it does so to show a Modal window with my extensions functionality in that modal.
I cannot use the background or popup scripts to do what I need to do so I have to use a content script which injects into the actual page DOM.
My issue so far is I have to be super careful with CSS class names and JS as well as I have discovered if the page has a CSS class matching the name of any of my extensions CSS, my extensions ends up over-riding the pages CSS!
I have seen that some other extensions that have to do a lot of HTML, CSS, JS into the content end up injecting into there own Iframe in the page which helps prevent this name collision.
Is using an Iframe the standard best practice in this case?
One of the features in my extensions is to do full-page screeenshots which require my contnet.js script to send a message to my background.js script which is responsibble for calling the CHrome API and taking the screenshot of the current scroll position in the pages viewport.
user clicks button in DOM modal windows
content.js sends message to background.js with the coordinates of the viewport.
background.js takes the screenshot with those coordinates. THen sends a message back to content.js.
content.js then scrolls down the page to the next area of the viewport for the next screenshot and then sends those new coordinates back to background.js.
this cycle continues until a shot of the whole page is made and stiched together and then sends back the URL of the new image to content.js when done.
Because both the Chrome API needs to sends messages back and forth between my content.js and background.js and then also if there is an iframe the iframe has to send messages back and forth with the page and the iframe.
Because of this I am not sure if I could use an iframe or not even?
Also if I did use an iframe, it would not load the content from a remote server but instead would be loaded into the page as html.
So is there a best practice for doing this?
Use inline styles instead
You can wrap your css in content.js then apply it to your target elements, it won't interfer the original design of the webpage
Use Shadow DOM
It provides encapsulation for js/css and makes it easy to ensure your components separate from the DOM of the main document.

how to set iframe src to local file

I have an iframe in my HTML, where i would like to play mpeg/mpg files from local folder, but i can't load the video into the iframe. when i set src="http://www.google.com", it is displayed in the iframe, but if i try src="file:///C:/Documents%20and%20Settings/jgabotero/Desktop/sample.jpg"
it doesn't display the image.
How can i set the src property of iframe to point to local files, specially the ones stored in IsolatedStorage?
Thank you in advance.
--
julie
i think you can't display files in iframe form your computer using file:// its a security issue.
I also think you can't display images in iframe, ue an html or ohp page, to do this, so put the image in a html file, and link the iframe to this html file.

Getting jQuery plugin to act on dynamically loaded (ajax) content

I have one jQuery plugin (colorbox) that loads a modal popup window (with an external html file). <-- works perfectly by itself. I have another jQuery plugin (jScrollPane) that loads custom scroll bars for divs. <-- it too works perfectly by itself. Both have a JS component and a CSS component.
My process thus far:
I tried to load and initialize the scroll bar jQuery and CSS from the eternal html (popup) and my div disappeared.
Then I tried to load the scroll bar jQuery in the parent window and initialize it in the colorbox callback...this time my div didn't disappear but the scroll bar and arrows (even OS standard arrows) did disappear.
Finally, I put the scroll bar CSS in <style> tags and shoved it inside the eternal html file's <body> tags. That works on all major browsers, however, now you can't exit the popup window. Arg!
So I think my question is: how do you get jQuery plugins and their CSS files to initialize on dynamically loaded content? What goes where (incl. the jQuery library itself)?
Thanks!
If you are using the "window.open" type of popup, then I would say make it a little simpler and bring it into your page as a JQueryUI Dialog box that pulls in your external html file are the content, loading it in the DIV and accessible within the general page context, inheriting the JQuery and CSS as well. The simple form of this should be like:
$("#id").load(url).dialog();
Where #id is the DIV that is hidden and will contain your dialog data, and URL is the external url to the html file in your popup.
Found the solution....
My question was specifically on integrating colorbox (a jQuery lightbox plugin) with jScrollPane (a jQuery custom scrollbar plugin). My ajax call to load content with the colorbox worked, however, the jScrollPane could not initiate because the required wasn't loaded (because the ajax call didn't pull any info from the head tags).
If other Stack Overflowers stumble across a similar issue this is what I did to solve it: used iframes instead of an ajax call. Ooops. duh.
I don't know if colorbox is the only plugin that pulls info only from body tags and not the head but I imagine many plugins work this way when working with external files. If this is your problem, use iframes to ensure that the data in your head tag is pulled.
Thanks Stack Overflow anyhoo! I still love you.

master page images not showing on child pages

This is probably something really simple but I cant see what!
Any images I have in a masterpage aren't showing up in child pages,
all I get is the box with the red cross in it.
I don't think Ive done anything different from usual and it's not something that's
happened in other sites so im kinda scratchin my head with it.
Any ideas are appreciated!
Kevin's got the essence of the problem right - your URL in your master page is likely relative to the location of the master page, and when it's included in the child page, the relative reference isn't correct anymore. The simplest solution for this sort of thing is to have your master page URLs be relative to the site, not the page. In other words, if you've been doing
<img src="images/picture1.gif">
You need to replace that with
<img src="/images/picture1.gif">
or something similar.
in the master page you use the image src similar to the below line and this will work. this same problem solved usig this way.
src="<%= Page.ResolveUrl("~")%>Images/myimage.png"
Did you give the image runat="server" and use a root relative "~/" path to the file?
The URL to your image is incorrect.
Try using absolute paths to your images.
I've had this problem when using a master file with content pages in different subdirectories.
If you use relative paths to your images, thay should be relative to the content page, not the master.
Edit: This is true if you use the img tag to display your images. asp:Image behaves better =)
It definitely sounds like you have a pathing problem. View the source to your rendered page and take a look at where it's trying to load the image from, that should help you fix your path.
If you set the right path then also you are getting the same problem then you can try this will definitely solve your problem:
Use double dots(..) before the starting of url.
If Content pages are located inside subfolders this problem arises. When a content page is rendered the markup is generated afresh for the master page content as well, and the location of an image may render differently as it appears in the master page. The best way is to replace with asp:Image control instead of HTML image tag. Then define the absolute starting with:~/ to actual location of the image. This should solve the problem. Please remove the entire image tag before inserting asp:Image as attributes are different for both.
Good Luck !!.
If you use image<img> tag instead of this, please use "style="background-image: url('/Images/welc.jpg');"in any other tag. This looks like a silly.But it works for me. I was also getting this problem,after using this thereafter I got image at all my child pages.

jQuery Thickbox with .ASHX image handler - shows garbage

I am using an .ASHX handler to return images from my ASP.NET app. When I use the browser to hit the URL directly (example):
http://localhost/myapp/GetImage.ashx?key=12
it works fine... image shows up on the page. but when I use that same link as a target in Thickbox... I get this:
alt text http://franceschina.net/temp/thickbox.png
the distilled version of ASHX the code:
byte[] img = (byte[])pp.PRODUCT_PHOTO1.ToArray();
context.Response.ContentType = "image/JPEG";
context.Response.OutputStream.Write(img, 0, img.Length);
any idea what I'm missing?
http://drupal.org/node/140371:
In the Thickbox module, the main *.js file, thickbox.js does not account for image urls created in drupal, e.g. via /image/view/2321/preview instead of /image.jpg (or *gif or *png). If thickbox.js does not see the file name itself (gif, jpg, png, jpeg) in the link anchor tag (the [a href ...] tag), it will treat the image like another mime type that is not an image. This causes Thickbox to spit out God-awful garbage on top of your page instead of a cool shadowbox (lightbox) effect.
Looks like the same issue you're having.
well I ended up using the iframe option of ThickBox to load my image with another page. I don't love this solution (it requires a separate page and extra code to determine the optimal height/width of the iFrame)... but it works and I don't have any more time to mess with it

Resources