Active7 years, 6 months ago
Please help.I am obviously no expert but using suggestions from this site, I think I am really close to doing the following
I want to display a PDF that is stored in a document library through an iframe. Currently this works without any issues when the PDF is stored in a layouts sub-folder. When I store it in a document library I'm only given the option to save it locally. Below is the test HTML I used to validate this.
Be able to open a dynamically generated PDF ina) a new Tab b) an iframe
Hopefully, I just need a couple of lines of the correct syntax and I will be there.
I am dynamically generating the PDF in a controller using itextSharp
CONTROLLER
VIEW
In response to your suggestion Darin, I changed the Controller to:
Having done that, your suggestions worked fine but I realise that I did not explain my intentions clearly enough. I have therefore changed the VIEW to reflect what i am trying to do.
Pete Davies
Pete DaviesPete Davies56144 gold badges1414 silver badges2626 bronze badges
1 Answer
Action:
To open in new Tab/Window:
To open in an iframe your code looks fine. Just make sure to set the Content-Disposition header to inline.
Darin DimitrovDarin Dimitrov878k233233 gold badges30753075 silver badges27912791 bronze badges
Not the answer you're looking for? Browse other questions tagged asp.net-mvcpdf or ask your own question.
When you create a document to be inside an
IFRAME
, any links in that frame will automatically open in that same frame. But with the attribute on the link (the element or element) you can decide where your links should open.You can choose to give your iframes a unique name with the attribute and then point your links at that frame with the ID as the value of the
target
attribute:id='page'>
target='page'>
If you add a target to an ID that doesn't exist in the current browser session, this will open the link in a new browser window, with that name. After the first time, any links that point to that named target will open in the same new window.
But if you don't want to name every window or every frame with an ID, you can still target some specific windows without needing a named window or frame. These are called the standard targets.
The Four Target Keywords
There are four target keywords that don't require a named frame. These keywords allow you to open links in specific areas of the web browser window that might not have an ID associated with them. These are targets that web browsers recognize:
_self
- This is the default target for any anchor tag. If you don't set the
target
attribute or you use this target, the link will open in the same window or frame that the link is in.
- This is the default target for any anchor tag. If you don't set the
_parent
- Iframes are embedded inside web pages. And you could embed an iframe in a page that is inside another iframe on another web page. When you set the
target
attribute to_parent
the link will open in the web page that is holding the iframe.
- Iframes are embedded inside web pages. And you could embed an iframe in a page that is inside another iframe on another web page. When you set the
_top
- In most situations with iframes, this target will open links in the same way that the
_parent
target does. But if there is anIFRAME
inside anIFRAME
, the_top
target opens links in the highest level window in the series, removing all the iframes.
- In most situations with iframes, this target will open links in the same way that the
_blank
- This is the most commonly used target—it opens the link in an entirely new window, similar to a popup.
How to Choose the Names of Your Frames
When you build a web page with iframes, it's a good idea to give each one a specific name. This helps you remember what they are for and allows you to send links to those specific frames.
I like to name my iframes for what they are for. For example:
id='links'>
id='external-document'>
Using HTML Frames With Targets
HTML5 makes frames and framesets obsolete, but if you're still using HTML 4.01, you can target specific frames in the same way you target iframes. You give the frames names with the
id
attribute:id='myFrame'>
Then, when a link in another frame (or window) has the same target, the link will open in that frame:
target='myFrame'>
The four target keywords also work with frames. The
_parent
opens in the enclosing frame, _self
opens in the same frame, _top
opens in the same window, but outside of the frameset, and _blank
opens in a new window or tab (depending upon the browser).Setting a Default Target
You can also set a default target on your web pages using the element. You set the
target
attribute to the name of the iframe (or frame in HTML 4.01) you want all links to open in. You can also set default targets of one of the four target keywords. Here's how to write a default target for a page:Open Pdf In Iframe Chrome
Adobe application initialization error windows. The element belongs in the
HEAD
of your document. It is a void element, so in XHTML, you would include the closing slash:Open Pdf In Iframe Javascript
/>