Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. set Qwebview url via js function
QtWS25 Last Chance

set Qwebview url via js function

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qwebview qquickwebviewqml + js
4 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • QjayQ Offline
    QjayQ Offline
    Qjay
    wrote on last edited by Qjay
    #1

    Hello all , i want to set the url of webview using javascript function . the function uses regex to get the url from a web page and then i want to provide that url to webview .

    below is the code

    import QtQuick 2.0
    import QtWebView 1.1
    
    Item {
    
        property string video
        function parsing()
            {
                var http = new XMLHttpRequest();
                var  url;
                http.onreadystatechange = function(){
                    /*
                      checks if the
                      request finished and response is ready ( readystate 4)
                      200: "OK"
                      */
                    if(http.readyState == 4 && http.status == 200)
                    {
                        var content = http.responseText;
                        url = content.match(/"http:\/\/www\.youtube\.com\/embed\/.+\"/);
                        console.log(url);
                    }
    
                    video = url;
                    console.log(video);
                };
    
                http.open('GET',"http://someurl/");
                http.send();
            }
    
        WebView {
            id: webView
            anchors.fill: parent
            url: "set url here "
    
        }
    }
    
    
    1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      Hi,
      [...]
      video = url;
      console.log(video);
      webView.url = video //webView is 'id' of your WebView{}
      [...]
      LA

      QjayQ 1 Reply Last reply
      0
      • ODБOïO ODБOï

        Hi,
        [...]
        video = url;
        console.log(video);
        webView.url = video //webView is 'id' of your WebView{}
        [...]
        LA

        QjayQ Offline
        QjayQ Offline
        Qjay
        wrote on last edited by
        #3

        @LeLev hey , how can i auto call the parsing() function i.e. when i load this qml the function should automatically get executed !!

        1 Reply Last reply
        0
        • ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #4

          Use 'Component.onCompleted' handler to assign directly your url, or to call a function which will do that.

          function setUrl(idOfWebView){

                   idOfWebView.url = "https://forum.qt.io"
          

          }

          WebView {
          id: myWebView
          anchors.fill: parent
          // url: "set url here "

          Component.onCompleted : { /* any JavaScript function or expressions */
                                                           //  myWebView.url = "https://forum.qt.io"      ( DIRECT )
                                        
                                                              //or u can call a function like this :
                                                       //    setUrl(myWebView)  // pass id of your webView to the function.    ( FUNCTION )
          
           }
          
          }
          

          LA

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved