AhmadMustafa commited on
Commit
8359520
·
1 Parent(s): 06a5ce9

update: iframe again

Browse files
Files changed (1) hide show
  1. app.py +34 -34
app.py CHANGED
@@ -528,40 +528,40 @@ def create_chat_interface():
528
  display: none !important;
529
  }
530
  """
531
- # js = """
532
- # function createIframeHandler() {
533
- # let iframe = document.getElementById('link-frame');
534
- # if (!iframe) {
535
- # iframe = document.createElement('iframe');
536
- # iframe.id = 'link-frame';
537
- # iframe.style.position = 'absolute';
538
- # iframe.style.width = '1px';
539
- # iframe.style.height = '1px';
540
- # iframe.style.right = '-100px';
541
- # iframe.style.bottom = '-100px';
542
- # iframe.style.display = 'none'; // Hidden initially
543
- # document.body.appendChild(iframe);
544
- # }
545
-
546
- # document.addEventListener('click', function (event) {
547
- # var link = event.target.closest('a');
548
- # if (link && link.href) {
549
- # try {
550
- # iframe.src = link.href;
551
- # iframe.style.display = 'block'; // Show iframe on link click
552
- # event.preventDefault();
553
- # console.log('Opening link in iframe:', link.href);
554
- # } catch (error) {
555
- # console.error('Failed to open link in iframe:', error);
556
- # }
557
- # }
558
- # });
559
-
560
- # return 'Iframe handler initialized';
561
- # }
562
- # """
563
-
564
- with gr.Blocks(fill_height=True, fill_width=True, css=css) as demo:
565
  chatbot = gr.Chatbot(
566
  elem_id="chatbot_box",
567
  layout="bubble",
 
528
  display: none !important;
529
  }
530
  """
531
+ js = """
532
+ function createIframeHandler() {
533
+ let iframe = document.getElementById('link-frame');
534
+ if (!iframe) {
535
+ iframe = document.createElement('iframe');
536
+ iframe.id = 'link-frame';
537
+ iframe.style.position = 'absolute';
538
+ iframe.style.width = '1px';
539
+ iframe.style.height = '1px';
540
+ iframe.style.right = '-100px';
541
+ iframe.style.bottom = '-100px';
542
+ iframe.style.display = 'none'; // Hidden initially
543
+ document.body.appendChild(iframe);
544
+ }
545
+
546
+ document.addEventListener('click', function (event) {
547
+ var link = event.target.closest('a');
548
+ if (link && link.href) {
549
+ try {
550
+ iframe.src = link.href;
551
+ iframe.style.display = 'block'; // Show iframe on link click
552
+ event.preventDefault();
553
+ console.log('Opening link in iframe:', link.href);
554
+ } catch (error) {
555
+ console.error('Failed to open link in iframe:', error);
556
+ }
557
+ }
558
+ });
559
+
560
+ return 'Iframe handler initialized';
561
+ }
562
+ """
563
+
564
+ with gr.Blocks(fill_height=True, fill_width=True, css=css, js=js) as demo:
565
  chatbot = gr.Chatbot(
566
  elem_id="chatbot_box",
567
  layout="bubble",