Skip to content Skip to sidebar Skip to footer

How To Create A Button In Javascript That Will Open Iframe When User Clicks On That Button?

I'm working on comments for posts on my website. How to create a button in javascript that will open iframe window with comments when user clicks on that button? Something like Fac

Solution 1:

Try using something like prettyPhoto:

http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/

If you scroll down on that page you will see an example where the loaded window displays an iFrame. Very handy for creating semi-ajax-like functionality to a website. You can use pretty much any lightbox clone out there for something like this, but I have found that prettyPhoto is the most robust and has a decent amount of support out there. This does use jQuery to work as well as it's own javascript file to function, but it is minimal.

Hope this helps.

Solution 2:

I would jquery .load, .post, .get or .ajax

under every article have a div class named comments and display none css on that div. when the user clicks the view comments button for that article, send a request to the server and ask for comments for that article id.

you will want to store the id of the article in an attribute of the view comments link so that you can pass the .load request the id of the article you want comments for.

<div articleid="5" class="view-com-button">view comments</div>
<div class="comment" articleid="5" style="display:none"></div>
$(".view-com-button").click(function(event){
$(".comment[articleid='$(this).attrib("articleid").load("comment.php", {( "idarticle" : $(this).attrib("articleid") )};
});

Post a Comment for "How To Create A Button In Javascript That Will Open Iframe When User Clicks On That Button?"