Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The code is given below, The target attribute is not working, any help will be useful

mainpage.html
<html>
<head>
<title>Main Frame</title>
</head>
<body align ="center">
<iframe src="buttons.html" style="border:2px solid red;  height:600px;width:300px; name="btn_frame"></iframe>
<iframe src="display.html" style="border:2px solid red;  height:600px;width:600px; name="display"></iframe>
</body>
</html>


button.html
<html>
<head>
<title>Options Page</title>
</head>
<body bgcolor = "cyan">
<p>
<a href="addmembers.html" target="display">Add Members</a><br><br><br>
</p>
</body>
</html>


What I have tried:

I tried by changing the target names and also checked the syntax.
Posted
Updated 7-May-20 3:59am

You need to give the iframe a "name" and use that name in the a tag "target"

How to Display a Web Page inside HTML iFrame - Tutorial Republic[^]
 
Share this answer
 
Comments
kirupabshankar 7-May-20 8:28am    
I gave the name as "display" for the iframe and assigned the same to the target, but still no use any idea?
F-ES Sitecore 7-May-20 8:46am    
If your html is exactly as posted it is invalid, you are missing a closing quote on the "style" attribute

<iframe src="buttons.html" style="border:2px solid red; height:600px;width:300px; name="btn_frame"></iframe>

should be

<iframe src="buttons.html" style="border:2px solid red; height:600px;width:300px;" name="btn_frame"></iframe>
kirupabshankar 7-May-20 9:01am    
I changed the same, but the same problem persists.
F-ES Sitecore 7-May-20 9:07am    
Well it works ok for me. Try the demo on w3schools, if that doesn't work it is a problem in your browser, if it does work then there is still some other issue in your code, maybe code you haven't posted.

https://www.w3schools.com/html/html_iframe.asp
You need to realize that an <iframe> is effectively a separate page from the page it is on - it can even have elements with the same ID's as the parent page and they will not be confused.

Now - if you have two iframe's on the same page - for normal interactions they don't know anything about each other. What they do have in common is the same parent.

So - for one frame to contact the other you must go through the parent. From the parent you can, for example, change the source of the other iframe.

Here's a references for you - to give you the idea if I wasn't clear enough:
Getting the URL of an iframe’s parent - Human Who Codes[^]
 
Share this answer
 
Comments
MadMyche 7-May-20 10:00am    
An important note is that if the webpage and the iframes within it come from more than one domain there may be some security configurations which will have to be adjusted ( Cross Frame Scripting)
Richard Deeming 7-May-20 10:23am    
Here's an example from 1998(!) which shows that you don't need to do anything special:
Iframes3 - Opening a link in one iframe in another iframe[^]

Using target on an <a> in one iframe will automatically open that link in a sibling iframe if the name is set correctly. You don't need to do anything special to go via the parent. :)
I found the solution by myself, thanks
F-ES Sitecore
for your comments. The real solution is we should use the "id" tag instead of "name" and that worked fine. May be this will be useful for the beginners like me.
 
Share this answer
 
Comments
Richard Deeming 7-May-20 10:24am    
This example from 1998 uses name, not id, and it still works perfectly:
Iframes3 - Opening a link in one iframe in another iframe[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900