Switching html pages inside the same (one) container html page - iframe

Ok let us say I have just one HTML page. Call it index.htm
This is the container page.(Is there another fancy name for container page ?)
I have 3 buttons on this page on top. Buttons A, B and C
If I click on Button A, I want to display a HTML page called fileX.htm inside the same index.htm page, right below it. But then if I click on Button B, I want to replace fileX.htm with file fileY.htm (in the same area where fileX.htm was displayed). Then if I click on Button C, I want to replace fileY.htm with fileZ.htm. Then I click on button B and filey.htm must replace fileZ.htm on so on.
I know how to do this with iFrames. I have also seen this done using tabs and a CSS file.
Both seem messy.
I know how to show just one file fileX.htm using embed tag.But the problem is switching from filex.htm to fileY.htm etc.
Is it possible to do this using embed or some other simple way such as an altered href tag or something ?
Thanks

You can by changing src attribute of embed when the button is clicked using Javascript
Edit: Working example
index.html
<embed type="text/html" src="test1.html" width="500" height="300" id="embed" />
<button id="test1">Test1</button>
<button id="test2">Test2</button>
<script>
const test1 = document.getElementById("test1");
const test2 = document.getElementById("test2");
const embed = document.getElementById("embed");
test1.addEventListener("click", (e) => {
embed.src = "test1.html";
});
test2.addEventListener("click", (e) => {
embed.src = "test2.html";
});
</script>
test1.html
<h1>test1</h1>
test2.html
<h1>test2</h1>
You can do the same with object and iframe AFAIK.

Related

Embed a PDF on a ASP.NET page

Im trying to embed a PDF on to my page, but the PDF just does not load. I have checked the file path which is correct.
When the page first loads, I get a blank grey embed field, however when I click on the embed, I get this (which stays like this):
<script>
var selected_doc_ref = "";
function getPDF() {
//selected_doc_ref = "395";
var DV_pdf_path = "../../../Document_Viewer/Risk_Assessment/RISK ASSESSMENT 1024.pdf";
var pdf = document.getElementById("pdf");
var clone = pdf.cloneNode(true);
clone.setAttribute('src', DV_pdf_path);
pdf.parentNode.replaceChild(clone, pdf)
}
</script>
<body onload="getPDF()">
<embed id="pdf" style="border-radius: 10px;position: relative;top:0;right:0;left:0;bottom:0;width:100%;height:620px;"/>
Any ideas where I am going wrong?
Thanks
As the browser does not refresh the embed tag when you add the src attribute to the <embed> tag after page load you have 2 options:
Set the src attribute on the <embed> tag directly so it is available from the beginning on. You could set the src through code behind or as a static value.
In your javascript, add the whole <embed> tag inside the getPDF() function instead of just the attribute src:
var e = document.createElement('embed');
e.attributes['src'] = src;
e.attributes['style'] = "border-radius: 10px;position: relative;top:0;right:0;left:0;bottom:0;width:100%;height:620px;";
document.getElementById("pdfContainer").appendChild(e);
Assuming that you have a element with id "pdfContainer" where you want to place the <embed> tag inside.

Control one iFrame from another iFrame

This works …
Link text
but this doesn't …
<script type="text/javascript">
window.onload = function() {
var a = document.getElementById("mylink");
a.onclick = function() {
parent.document.getElementById('frameName').src = 'page.html';
}
}
</script>
<a id="mylink" href="page.html">LINK</a>
Any idea why I can't get the element by id from one iFrame to another? Also I know very little code so I apologize in advance if its obvious.
First i would make sure that the security of the site within the IFrame allows you to do this kind of stuff. Check out this link:
Overcoming "Display forbidden by X-Frame-Options"
Next, i would worry about the target of your anchor tag. With specifying it will default to self. In your second piece of code the target will be _self. Thus, when you click the link your javascript will want to change the source of the IFrame while the link will want to change the entire page. I would pick either a JS or HTML implemetation of linking and not both. Here is something that i put together to show one way of changing the iFrame without an actual anchor tag.
<html>
<body>
<iframe id="frameName" src="page.html"></iframe>
<button onclick="changeFrame()">LINK</button>
<script>
function changeFrame() {
document.getElementById('frameName').src ='page2.html';
}
</script>
</body>
</html>

asp.net vb how to make hidden additional attachment hidden and visible?

Hi I tried in afew manners but wasnt able to make it work.
I want to make 5 attachment options in that 4 out of the 5 are hidden.
but when he clicks "more attachment" link it will show the other 4.
any ideas?
Im using ASP.NET with VB
plus if you need my code let me know!
thank you!
you can do that with many ways, one of them is enclose your 4 attachments within a div styled with display:none and by using javascript shows them in onclick events of more attachment link, something like this
<div style="display:none" id="moreattchdiv">
<!-- 1st attachment -->
<!-- 2nd attachment -->
<!-- 3rd attachment -->
<!-- 4th attachment -->
</div>
<div onclick="showmore()">more attachments</div>
<script>
function showmore()
{
var moreattachdiv = $('#moreattchdiv');
if(moreattachdiv.is(':visible'))
{
moreattachdiv.hide();
}
else
{
moreattachdiv.show();
}
}
</script>
Note I am using jquery in my script
you can test that example here
Update
insert this line into header tag of your page.If you are using master page insert it into its header tag
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
If you would like to do it without jquery replace the showmore() function with this code
function showmore()
{
var moreattachdiv = document.getElementById('moreattchdiv')
if(moreattachdiv.style.display=='none')
{
moreattachdiv.style.display=''
}
else
{
moreattachdiv.style.display='none'
}
}
you can test it here
You can wrap the hidden 4 attachments in a div that has the style set to display: none, then when you click the more attachments link, it would set the style of that hidden div to display: block.
Here's an example:
http://jsfiddle.net/kmmzH/

How to open a link like www.gmail.com from code?

I want to open an URL like gmail.com when a user clicks on a button. How can I open this link in new tab from code (I want to read link from database)?
You can use:
Response.Redirect
Method in ASP.NET to navigate to another web page.
call JavaScript from Page Behind Code Like this.
Page.ClientScript.RegisterStartupScript(this.GetType(),
"onLoad", "openNewWindow()", true);
<script language="JavaScript">
<!-- hide
function openNewWindow() {
popupWin = window.open('http://webdesign.about.com/',
'open_window',
'menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=640, height=480, left=0, top=0')
}
// done hiding -->
</script>
you can also do it using window.location("http://www.yourpath.com")
As suggested before me use
Response.Redirect("http://www.gmail.com")
this should work as the method is designed also for absolute urls. Do not leave the http:// prefix.
<input type="button" onclick="openlink()"/>
<script>
function openlink()
{
document.location.href = "http://www.gmail.com";
}
</script>
just execute the below line on button click
window.location="http://www.google.com";

How can I add a random number to an ASP.NET menu item url on each click

One step to prevent caching (in addition to adding the appropriate headers etc..) is to add a random number to the end of my URLs.
I'm using an ASP.NET menu and would like to add a random number to each menu item's navigate URL as it is clicked.
I can do this in the MenuItemDataBound event, but haven't had much luck doing the same with the MenuItemClicked Event.
Answer (can't answer my own question for 8 hours, and I don't have time to wait that long so here's my server side solution.)
To do this server side, I've had to remove the sitemap and the databinding from the menu.
I simply added all of the items from the sitemap as menuitems to the items collection in the menu markup removing the url property. The key here is removing the url property.
<asp:menu>
<items>
<asp:menuitem Text="Home" ToolTip="Go Home" Selectable="True" />
</items>
</asp:menu>
Then in your code behind you can handle the MenuItemClicked event (which should now fire, because there is no longer a navigateurl in the markup).
In the MenuItemClicked event codebehind I simply do the following:
string TimeStamp = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
// get iframe control - must have 'runat=server' attribute
HTMLControl display = CType(this.FindControl("display"), HTMLControl);
// dispatch menuitem
switch (e.item.valuepath)
{
case "Home":
display.attributes("src") = "home.aspx?=" + TimeStamp()
break;
.
.
.
}
This is the server side solution with an iframe.
I don't know if you're considering client-side URL manipulation as an option, but running this little bit of JavaScript on each page load would give you the behavior you're looking for by appending a timestamp to each of the links. You can modify it to target links in a specific area/div of the site, but this example will change them all:
<!-- include the jQuery library -->
<script type="text/javascript">
$(function(){
var time = new Date().getTime();
$('a').each(function() {
var append = (this.href.indexOf('?') > -1 ? '&' : '?');
$(this).attr('href', this.href + append + 't=' + time.toString());
});
});
</script>
Since every time the page loads the timestamp will be different, you should always get a unique set of links.
EDIT Here's a working jsFiddle demoing the behavior: http://jsfiddle.net/2HzqU/2/
I don't think that's the best solution. Have you tried using something like this:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();

Resources