0

<a href="chat9867.php?user=Emma">Chat With Emma</a> It is a code to access profile chatting page in my site! Editing & removing this code is locked due to their security reasons.

But I want it to be inside of an iframe:- <iframe src="chat9867.php?user=Emma" width="100%" class="chat-iframe"></iframe>. So it will be easier for an user to chat with the another person. As it is locked, I have to do it manually by javascript.

So how can I create an iframe fetching the URL from <a href="chat9867.php?user=Emma">...</a>"?

Is there any way to do it using javascript/jquery?

  • 1
    Possible duplicate of [Creating an IFRAME using JavaScript](https://stackoverflow.com/questions/8726455/creating-an-iframe-using-javascript) – DNKROZ Aug 23 '17 at 12:53

3 Answers3

0

You can create iframe dynamically using plain JS or jQuery.

I will show for jQuery.

jQuery('<iframe>')
    .attr('src', jQuery('your_a_selector').attr('href'))
    .attr('width', '100%')
    .addClass('chat-iframe')
    .appendTo('#elementWhereAppendIt');

#elementWhereAppendIt is selector where new iframe will be placed to.

unalignedmemoryaccess
  • 7,246
  • 2
  • 25
  • 40
0

Here you go with a solution https://jsfiddle.net/Ls16u3ew/

$('body').append('<iframe width="100%" class="chat-iframe" src="' + $('a').prop('href') + '"></iframe>')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="chat9867.php?user=Emma">Chat With Emma</a>

I created the iframe on the fly (dynamically) & added src to it using anchor tag href.

Hope this will help you.

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
  • When I used the `` jQuery, then all Bootstrap Modals in my site stopped working! So I can't use it. –  Aug 23 '17 at 13:57
  • @user8427031 . Use some other `jQuery` version which suits your `bootstrap`. I used `jQuery` just for running the code, any version of `jQuery` will be fine for my code. – Shiladitya Aug 23 '17 at 14:07
  • Can you provide me some other `jQuery`s? –  Aug 23 '17 at 14:22
0

You can use jquery .attr() for this..

$('.iframe').attr('src',$('.chatLink').attr('href'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="chat9867.php?user=Emma" class="chatLink">Chat With Emma</a>
<iframe src="" class="iframe"></iframe>
Super User
  • 9,448
  • 3
  • 31
  • 47
  • I already told, it is locked, so I can't edit it. And you've included a `class="chatLink"` inside the HTML. So, it is totally worthless! –  Aug 23 '17 at 14:08