AhmadMustafa commited on
Commit
8a0a25e
·
1 Parent(s): d6eca8f

change: js to var

Browse files
Files changed (1) hide show
  1. app.py +32 -1
app.py CHANGED
@@ -493,8 +493,39 @@ def create_chat_interface():
493
  flex-grow: 1 !important;
494
  }
495
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
496
 
497
- with gr.Blocks(fill_height=True, fill_width=True, css=css, js="./index.js") as demo:
 
 
 
498
  chatbot = gr.Chatbot(
499
  elem_id="chatbot_box",
500
  layout="bubble",
 
493
  flex-grow: 1 !important;
494
  }
495
  """
496
+ js = """
497
+ function createIframeHandler() {
498
+ let iframe = document.getElementById('link-frame');
499
+ if (!iframe) {
500
+ iframe = document.createElement('iframe');
501
+ iframe.id = 'link-frame';
502
+ iframe.style.position = 'absolute';
503
+ iframe.style.width = '1px';
504
+ iframe.style.height = '1px';
505
+ iframe.style.right = '-100px';
506
+ iframe.style.bottom = '-100px';
507
+ iframe.style.display = 'none'; // Hidden initially
508
+ document.body.appendChild(iframe);
509
+ }
510
+
511
+ document.addEventListener('click', function (event) {
512
+ var link = event.target.closest('a');
513
+ if (link && link.href) {
514
+ try {
515
+ iframe.src = link.href;
516
+ iframe.style.display = 'block'; // Show iframe on link click
517
+ event.preventDefault();
518
+ console.log('Opening link in iframe:', link.href);
519
+ } catch (error) {
520
+ console.error('Failed to open link in iframe:', error);
521
+ }
522
+ }
523
+ });
524
 
525
+ return 'Iframe handler initialized';
526
+ }
527
+ """
528
+ with gr.Blocks(fill_height=True, fill_width=True, css=css, js=js) as demo:
529
  chatbot = gr.Chatbot(
530
  elem_id="chatbot_box",
531
  layout="bubble",