Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Newbie Question: Howto make Javascript work?
QtWS25 Last Chance

Newbie Question: Howto make Javascript work?

Scheduled Pinned Locked Moved Qt WebKit
5 Posts 3 Posters 6.9k 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.
  • C Offline
    C Offline
    cuwe
    wrote on last edited by
    #1

    Howdy!

    Sorry to make the forum a sample lab ;-) I am trying to make a simple process work:

    1. Open a webpage in the main window
    2. The page opens an empty popup via js:window.open
    3. The page uses js to do some changes to the popup content
    4. The popup uses js to navigate the main window to a new url
    5. The main window gets closed, but the popup remains

    I have steps 1 and 2, the latter by implementing QWebView::createWindow. The script below used for testing, you wont get an error and no text appears in the popup. It works fine with Firefox, but also fails with Arora. Been looking the net up and down, but I cant find a simple code sample that explains how to make sure that javascript references work with the corresponding Qt objects.

    Any hints are very welcome :)

    @

    alert("Start by hitting ok");

    var win;

    var sOptions = "resizable=no,scrollbars=yes,width=260,height=225";

    try {

    win = window.open('', 'windowidzero', sOptions);
    win.[removed]("text into popup");
    

    } catch (e) {

    alert(e.description + "/" + e.name + "/" + e.number);

    }

    @

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Is javascript enabled in your QWebView? What does this return for you?:

      @
      m_webView->page()->settings()->testAttribute( QWebSettings::JavascriptEnabled );
      @

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cuwe
        wrote on last edited by
        #3

        [quote author="ZapB" date="1311426271"]Is javascript enabled in your QWebView? What does this return for you?:
        [/quote]

        Jepp, its enabled and working. I get the alert and the window.open creates a new window. The win variable contains a reference, but win document write does nothing.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cuwe
          wrote on last edited by
          #4

          I made some progress and would like to share the results.

          Making window.open work
          I think there is no way around subclassing QWebView and QWebClass when you want to use them. The most simple way to get a new window is by implementing a new QWebView::createWindow(...) like

          @
          QWebView* CWebView::createWindow(QWebPage::WebWindowType type)
          {
          return new QWebView(NULL);
          }
          @

          You should do something with the type parameter, which would be of QWebPage::WebBrowserWindow or QWebPage::WebModalDialog - which makes clear why you might need it :)

          Writing into the new window
          This generally works, but only after the primary page has been fully loaded. You should put your commands into a function and call that from the window onload function. I am not sure if this is a bug in its sense, but did not see this restriction in Firefox or Opera.

          Resizing and closing the window
          If you set a size for the popup in javascript, this will not use it unless you implement a slot for the geometryChangeRequested signal. Same for closing the popup from js: implement a slot for the windowCloseRequested signal.

          Next on my list is manipulating the DOM using [removed])

          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            Yugan
            wrote on last edited by
            #5

            Hi Guys,

            Using webkit in QT5. Is it possible to open a new window when every time javascript opens a new window with out prompting for credentials.

            Will be fine if new window loads within application without asking for credentials.

            Yugan.

            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